summaryrefslogtreecommitdiff
path: root/DiscoBot/Commands.cs
blob: 6ba2b8ad65fe2f6350759dbda7ffab73f990035c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;


namespace DiscoBot
{
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Threading;

    using Discord.Audio;

    public class Info : ModuleBase
    {
        [Command("say"), Summary("Echos a message.")]
        [Alias("s")]
        public async Task Say([Remainder, Summary("The text to echo")] string echo)
        {
            var a = Context.User.Username;

            await ReplyAsync(echo);
        }
    }

    public class Roll : ModuleBase
    {
        [Command("r"), Summary("Würfelt ")]
        [Alias("R", "Roll", "roll", "Würfle")]
        public async Task Say([Remainder, Summary("Weapon")] string roll)
        {
            await ReplyAsync("```xl\n" + Misc.Roll(roll) + "\n```");
        }
    }

    public class SetGeneral : ModuleBase
    {
        [Command("general"), Summary("Set General ")]
        public async Task Say([Remainder, Summary("Set General")] int i = 0)
        {
            DSA.GeneralContext = this.Context;
            await this.Context.Channel.SendMessageAsync($"```xl\n Der Dachs hat in '{this.Context.Channel.Name}' ein Zuhause gefunden. Gm Nachrichten werden nun auch in diesem Channel gepostet. \n```");
        }
    }

    [SuppressMessage("ReSharper", "PublicMembersMustHaveComments", Justification = "OK")]
    public class TestTalent : ModuleBase
    {
        [Command("t"), Summary("Würfelt ein Talent-/Zauberprobe")]
        [Alias("T", "Talent", "talent", "zauber", "z", "versuche")]
        public async Task Say([Summary("Talent oder Zaubername")] string talent, int erschwernis = 0)
        {
            string res = Gm.CheckCommand(DSA.relation[Context.User.Username], Commands.Talent, talent, erschwernis);
            await this.ReplyAsync("```xl\n" + res + "\n```");
            
            var tmessages = this.Context.Channel.GetMessagesAsync(10);
            Task.WaitAll(tmessages.ToArray());
            var list = tmessages.ToEnumerable().ToList();
            var messages = new List<IMessage>();
            foreach (var task in list)
            {
                messages.AddRange(task.ToList());
            }

            //await this.Context.Channel.DeleteMessagesAsync(messages.Where(x => x.Content[0].Equals('!') && (x.Author as SocketGuildUser).Roles.ToList().Exists(v => v.Name.Equals("Meister"))));
        }
    }

    public class TestEigenschaft : ModuleBase
    {
        [Command("e"), Summary("Würfelt eine Eifenschaftsprobe")]
        [Alias("E", "Eigenschaft", "eigenschaft", "eigen")]
        public async Task Say([Summary("Eigenschafts kürzel und Erschwernis")] string talent, int erschwernis = 0)
        {
            var chr = DSA.chars.Find(x => x.Name.Equals(DSA.relation[Context.User.Username]));
            string res = chr.TestEigenschaft(talent, erschwernis);
            await this.ReplyAsync("```xl\n" + res + "\n```");

        }
    }

    public class Angriff : ModuleBase
    {
        [Command("a"), Summary("Würfelt ein Angriff")]
        [Alias("At", "at", "Angriff", "angriff", "attackiere_mit", "attacke", "Attacke")]
        public async Task Say([Summary("Weapon")] string weapon, int erschwernis = 0)
        {
            await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.Name.Equals(DSA.relation[Context.User.Username])).Angriff(weapon, erschwernis) + "\n```");

        }
    }
    public class Parade : ModuleBase
    {
        // ~say hello -> hello
        [Command("p"), Summary("Würfelt eine Parade Probe")]
        [Alias("P", "Parade", "parade", "pariere_mit")]
        public async Task Say([Summary("Parade Weapon")] string talent, int erschwernis = 0)
        {
            await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.Name.Equals(DSA.relation[Context.User.Username])).Parade(talent, erschwernis) + "\n```");

        }
    }
    public class Fernkampf : ModuleBase
    {
        // ~say hello -> hello
        [Command("f"), Summary("Führt eine Fernkampfprobe aus")]
        [Alias("F", "fernkampf", "Fernkampf", "schieße", "schieße_mit")]
        public async Task Say([Summary("Fernkampfwaffe")] string waffe, int erschwernis = 0)
        {
            // ReplyAsync is a method on ModuleBase
            await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.Name.Equals(DSA.relation[Context.User.Username])).Fernkampf(waffe, erschwernis) + "\n```");
        }
        public async Task Say([Summary("Fernkampfwaffe")] string charName, string waffe, ICommandContext context, int erschwernis = 0)
        {
            // ReplyAsync is a method on ModuleBase
            await context.Channel.SendMessageAsync("Hello World\n");
            await context.Channel.SendMessageAsync("```xl\n" + DSA.chars.Find(x => x.Name.Equals(charName)).Fernkampf(waffe, erschwernis) + "\n```");
        }
    }

    public class Voice : ModuleBase
    {
        public static IAudioClient client { get; set; }
        [Command("join", RunMode = RunMode.Async)]
        public async Task JoinChannel(IVoiceChannel channel = null)
        {
            var msg = this.Context.Message;
            // Get the audio channel
            channel = channel ?? (msg.Author as IGuildUser)?.VoiceChannel;
            if (channel == null) { await msg.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return; }

            // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
            var audioClient = await channel.ConnectAsync();
            client = audioClient;
        }

        [Command("leave", RunMode = RunMode.Async)]
        public async Task LeaveChannel(IVoiceChannel channel = null)
        {
            // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
            client.StopAsync();
        }

        [Command("play")]
        public async Task PlayAudio(string path)
        {
            SendAsync(client, path);
        }

        private Process CreateStream(string path)
        {
            var ffmpeg = new ProcessStartInfo
                             {
                                 FileName = "ffmpeg",
                                 Arguments = $"-i {path}  -ac 2 -f s16le -ar 48000 -ab 620000 pipe:1",
                                 UseShellExecute = false,
                                 RedirectStandardOutput = true,
                             };
            return Process.Start(ffmpeg);
        }

        private async Task SendAsync(IAudioClient client, string path)
        {
            // Create FFmpeg using the previous example
            var ffmpeg = CreateStream(path);
            var output = ffmpeg.StandardOutput.BaseStream;
            var discord = client.CreatePCMStream(AudioApplication.Music);
            await output.CopyToAsync(discord);
            await discord.FlushAsync();
        }
    }


    [Group("gmtr")]
    public class Sample : ModuleBase
    {
        // ~sample square 20 -> 400
        [Command("square"), Summary("Squares a number.")]
        public async Task Square([Summary("The number to square.")] int num)
        {
            // We can also access the channel from the Command Context.
            await Context.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}");
        }

        [Command("userinfo"), Summary("Returns info about the current user, or the user parameter, if one passed.")]
        [Alias("user", "whois")]
        public async Task UserInfo([Summary("The (optional) user to get info for")] IUser user = null)
        {
            var userInfo = user ?? Context.Client.CurrentUser;
            await ReplyAsync($"{userInfo.Username}#{userInfo.Discriminator}");
        }
    }

    public class List : ModuleBase
    {
        // ~say hello -> hello
        [Command("list"), Summary("gibt eine Auflistung  aus")]
        public async Task Say([Summary("Aktion")] string prop)
        {
            var res = new List<string>();
            switch (prop.ToLower())
            {
                case "chars":
                case "Chars":
                    res.AddRange(DSA.chars.Select(x => x.Name));
                    break;
                case "t":
                case "ta":
                case "talent":
                case "zauber":
                    res.AddRange(
                        ((Character)DSA.chars.Find(x => x.Name.Equals(DSA.relation[this.Context.User.Username])))
                        .Talente.Select(s => s.name + "\t " + s.value + "\t " + s.probe));
                    break;
                case "w":
                case "waffe":
                case "waffen":
                    res.AddRange(
                        ((Character)DSA.chars.Find(x => x.Name.Equals(DSA.relation[this.Context.User.Username])))
                        .Kampftalente.Select(s => s.name));
                    break;
                case "fern":
                    res.AddRange(
                        ((Character)DSA.chars.Find(x => x.Name.Equals(DSA.relation[this.Context.User.Username])))
                        .Talente.Select(s => s.name));
                    break;
                case "v":
                case "vt":
                case "vor":
                case "vorteil":
                    res.AddRange(
                        ((Character)DSA.chars.Find(x => x.Name.Equals(DSA.relation[this.Context.User.Username])))
                        .Vorteile
                        .Select(s => s.name + "\t " + (s.value == 0 ? "" : s.value.ToString())));
                    break;

                default:
                    res.Add($"Kommando {prop} nicht gefunden");
                    break;
            }

            //await this.ReplyAsync(res.Aggregate((seed, next) => seed + "\n" + next));
            var sb = new StringBuilder();
            foreach (string re in res)
            {
                if (sb.Length + re.Length > 1798)
                {
                    await this.ReplyTimed(sb.ToString(), TimeSpan.FromSeconds(90));
                    sb.Clear();
                }

                sb.AppendLine(re);
            }

            await this.ReplyTimed(sb.ToString(), TimeSpan.FromSeconds(90));
        }

    }

    public class Gm : ModuleBase
    {
        // ~say hello -> hello
        [Command("gm"), Summary("Führt eine probe aus")]
        [Alias("GM", "as", "As", "als")]
        public async Task Say([Summary("Fernkampfwaffe")] string name, string command, string waffe, int erschwernis = 0)
        {
            if (!(this.Context.User as SocketGuildUser).Roles.ToList().Exists(v => v.Name.Equals("Meister")))
            {
                await ReplyAsync("```xl\n Keine ausreichenden Berechtigunen\n```");
                return;
            }

            command = command.ToLower();
            string res;
            switch (command)
            {
                case "f":
                case "fern":
                case "fernkampf":
                    res = CheckCommand(name, Commands.Fernkampf, waffe, erschwernis);
                    break;
                case "t":
                case "ta":
                case "talent":
                    res = CheckCommand(name, Commands.Talent, waffe, erschwernis);
                    break;
                case "e":
                case "ei":
                case "eigenschaft":
                    res = CheckCommand(name, Commands.Eigenschaft, waffe, erschwernis);
                    break;
                case "z":
                case "za":
                case "zauber":
                case "magie":
                case "m":
                    res = CheckCommand(name, Commands.Talent, waffe, erschwernis);
                    break;
                case "a":
                case "at":
                case "an":
                case "angrif":
                case "angriff":
                    res = CheckCommand(name, Commands.Angriff, waffe, erschwernis);
                    break;
                case "p":
                case "pa":
                case "parade":
                    res = CheckCommand(name, Commands.Parade, waffe, erschwernis);
                    break;
                case "talente":
                    throw new NotImplementedException();
                default:
                    res = $"Kommando {command} nicht gefunden";
                    break;
            }

            if (DSA.GeneralContext != null)
            {
                if (DSA.GeneralContext.Channel.Id != Context.Channel.Id)
                {
                    await DSA.GeneralContext.Channel.SendMessageAsync("```xl\n" + res + "\n```");
                }

                await ReplyAsync("```xl\n" + res + "\n```");
            }
            else
            {
                await ReplyAsync("```xl\n" + res + "\n```");
            }
        }

        public static string CheckCommand(string name, Commands command, string waffe, int erschwernis = 0)
        {
            var comp = new SpellCorrect();
            var chr = DSA.chars.OrderBy(x => comp.Compare(x.Name, name)).First();
            switch (command)
            {
                case Commands.Talent:
                    return chr.TestTalent(waffe, erschwernis);
                case Commands.Eigenschaft:
                    return chr.TestEigenschaft(waffe, erschwernis);
                case Commands.Angriff:
                    return chr.Angriff(waffe, erschwernis);
                case Commands.Parade:
                    return chr.Parade(waffe, erschwernis);
                case Commands.Fernkampf:
                    return chr.Fernkampf(waffe, erschwernis);
            }

            return $"{name} verwendet {waffe}";
        }
    }

    public class GenerateNpc : ModuleBase
    {
        // ~say hello -> hello
        [Command("npc"), Summary("Erstellt ein NPC")]
        [Alias("Npc", "NPc", "NPC", "nPC")]
        public async Task Say([Summary("Create Random")] string npcName, int mean = 9, int stDv = 1)
        {
            DSA.chars.Add(new NPC(npcName, mean, stDv));
            await this.ReplyAsync($"{npcName} wurde zufällig generiert");
        }
    }

    public class CopyNpc : ModuleBase
    {
        // ~say hello -> hello
        [Command("npc"), Summary("Erstellt ein NPC")]
        [Alias("Npc", "NPc", "NPC", "nPC")]
        public async Task Say([Summary("Create Copy")] string npcName, string source, int stDv = 1)
        {
            if (DSA.chars.Exists(x => x.Name.Equals(npcName)))
            {
                throw new Exception("Char gibt es schon");
            }

            var comp = new SpellCorrect();
            var chr = DSA.chars.OrderBy(x => comp.Compare(x.Name, source)).First();
            DSA.chars.Add(new Character(chr as Character, npcName, stDv));
            await ReplyAsync($"{npcName} wurde als variierte Kopie von {source} erstellt");
        }
    }

    public class NpcAction : ModuleBase
    {
        // ~say hello -> hello
        [Command("npc"), Summary("Führt eine NPC-Probe aus")]
        [Alias("Npc", "NPc", "NPC", "nPC")]
        public async Task Say([Summary("Aktion")] string NpcName, string command, string Aktion, int erschwernis = 0)
        {
            string test = "";
        }
    }

    /*public class AudioModule : ModuleBase<ICommandContext>
    {
        // Scroll down further for the AudioService.
        // Like, way down
        private readonly AudioService _service;

        // Remember to add an instance of the AudioService
        // to your IServiceCollection when you initialize your bot
        public AudioModule(AudioService service)
        {
            _service = service;
        }

        // You *MUST* mark these commands with 'RunMode.Async'
        // otherwise the bot will not respond until the Task times out.
        [Command("join", RunMode = RunMode.Async)]
        public async Task JoinCmd()
        {
            await _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel);
        }

        // Remember to add preconditions to your commands,
        // this is merely the minimal amount necessary.
        // Adding more commands of your own is also encouraged.
        [Command("leave", RunMode = RunMode.Async)]
        public async Task LeaveCmd()
        {
            await _service.LeaveAudio(Context.Guild);
        }

        [Command("play", RunMode = RunMode.Async)]
        public async Task PlayCmd([Remainder] string song)
        {
            await _service.SendAudioAsync(Context.Guild, Context.Channel, song);
        }
    }*/

    public enum Commands
    {
        Talent,
        Eigenschaft,
        Angriff,
        Parade,
        Fernkampf,
        KeinChar
    }
}