1 module main; 2 3 import std.stdio, 4 std.functional, 5 std.algorithm, 6 std.string, 7 std.format, 8 std.conv, 9 std.array, 10 core.time; 11 12 import std.experimental.logger; 13 14 import vibe.core.core; 15 import vibe.http.client; 16 // import dcad.types : DCAFile; 17 18 19 import dscord.core; 20 21 import core.sys.posix.signal; 22 import etc.linux.memoryerror; 23 24 class BasicPlugin : Plugin { 25 this() { 26 super(); 27 } 28 29 @Command("test") 30 @CommandDescription("HI") 31 void onTestCommand(CommandEvent event) { 32 event.msg.reply(event.cmd.description); 33 } 34 35 @Command("whereami") 36 void onWhereAmI(CommandEvent event) { 37 auto chan = this.userVoiceChannel(event.msg.guild, event.msg.author); 38 if (chan) { 39 event.msg.reply(format("Your in channel `%s`", chan.name)); 40 } else { 41 event.msg.reply("You are not in a voice channel!"); 42 } 43 } 44 45 @Listener!MessageCreate() 46 void onMessageCreate(MessageCreate event) { 47 this.log.infof("Got message: %s", event.message.mentioned); 48 } 49 50 Channel userVoiceChannel(Guild guild, User user) { 51 auto state = guild.voiceStates.pick(s => s.userID == user.id); 52 if (!state) return null; 53 return state.channel; 54 } 55 } 56 57 58 void main(string[] args) { 59 static if (is(typeof(registerMemoryErrorHandler))) 60 registerMemoryErrorHandler(); 61 62 if (args.length <= 1) { 63 writefln("Usage: %s <token>", args[0]); 64 return; 65 } 66 67 BotConfig config; 68 config.token = args[1]; 69 Bot bot = new Bot(config, LogLevel.trace); 70 bot.loadPlugin(new BasicPlugin); 71 bot.run(); 72 runEventLoop(); 73 return; 74 }