1 module main;
2 
3 import std.stdio,
4        std.algorithm,
5        std..string,
6        std.format,
7        std.conv,
8        std.array,
9        std.process,
10        core.time;
11 
12 import vibe.core.core;
13 import vibe.http.client;
14 import dcad.types : DCAFile;
15 
16 import dscord.core,
17        dscord.util.process,
18        dscord.voice.youtubedl;
19 
20 import core.sys.posix.signal;
21 import etc.linux.memoryerror;
22 
23 
24 class BasicPlugin : Plugin {
25   DCAFile sound;
26 
27   this() {
28     super();
29   }
30 
31   @Command("test")
32   @CommandDescription("HI")
33   void onTestCommand(CommandEvent event) {
34     auto chan = this.userVoiceChannel(event.msg.guild, event.msg.author);
35 
36     if (!chan) {
37       event.msg.reply("You are not in a voice channel!");
38       return;
39     }
40 
41     auto sound = new DCAPlayable(new DCAFile(File("test.dca", "r")));
42     auto vc = chan.joinVoice();
43 
44     if (vc.connect()) {
45       event.msg.replyf("OK: %s", vc);
46       vc.play(sound).disconnect();
47     } else {
48       event.msg.reply("it dont work");
49     }
50   }
51 
52   @Command("whereami")
53   void onWhereAmI(CommandEvent event) {
54     auto chan = this.userVoiceChannel(event.msg.guild, event.msg.author);
55     if (chan) {
56       event.msg.reply(format("Your in channel `%s`", chan.name));
57     } else {
58       event.msg.reply("You are not in a voice channel!");
59     }
60   }
61 
62   Channel userVoiceChannel(Guild guild, User user) {
63     auto state = guild.voiceStates.pick(s => s.userID == user.id);
64     if (!state) return null;
65     return state.channel;
66   }
67 }
68 
69 
70 void main(string[] args) {
71   static if (is(typeof(registerMemoryErrorHandler)))
72       registerMemoryErrorHandler();
73 
74   if (args.length <= 1) {
75     writefln("Usage: %s <token>", args[0]);
76     return;
77   }
78 
79   BotConfig config;
80   config.token = args[1];
81   config.cmdPrefix = "";
82   Bot bot = new Bot(config, LogLevel.trace);
83   bot.loadPlugin(new BasicPlugin);
84   bot.run();
85   runEventLoop();
86   return;
87 }