summaryrefslogtreecommitdiff
path: root/DiscoBot/Audio/AudioModule.cs
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-04-11 14:19:57 +0200
committerTrueDoctor <d-kobert@web.de>2018-04-11 14:19:57 +0200
commit351067a5203307fc0c1a14ae2be84eae71246af9 (patch)
treea17b63d94b41c87215a03fd2a19edab9f4d53c30 /DiscoBot/Audio/AudioModule.cs
parentaa236f67bf1829e2a7c6e9a5f82d109b39147b11 (diff)
Added possibillity for service based soundplaying
Diffstat (limited to 'DiscoBot/Audio/AudioModule.cs')
-rw-r--r--DiscoBot/Audio/AudioModule.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/DiscoBot/Audio/AudioModule.cs b/DiscoBot/Audio/AudioModule.cs
new file mode 100644
index 0000000..0c3814f
--- /dev/null
+++ b/DiscoBot/Audio/AudioModule.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Threading.Tasks;
+
+using DiscoBot;
+using DiscoBot.Audio;
+using DiscoBot.Auxiliary;
+using DiscoBot.Commands;
+
+using Discord;
+using Discord.Commands;
+
+public class AudioModule : ModuleBase
+{
+ // 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;
+ Dsa.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)
+ {
+ if (Dsa.GeneralContext == null)
+ {
+ Dsa.GeneralContext = this.Context;
+ }
+
+ var sounds = Enum.GetValues(typeof(Sound));
+ var soundList = new List<Sound>();
+ foreach (var sound in sounds)
+ {
+ soundList.Add((Sound)sound);
+ }
+
+ var sc = new SpellCorrect();
+
+ var tSound = soundList.OrderBy(x => sc.Compare(song, x.ToString())).First();
+
+ if (sc.Compare(song, tSound.ToString()) > SpellCorrect.ErrorThreshold)
+ {
+ await _service.SendAudioAsync(Context.Guild, Context.Channel, song);
+ }
+
+ await SoundEffects.Play(tSound);
+ }
+} \ No newline at end of file