blob: f2097b793c16d1c37387f181bdc7d79d77d4dfb0 (
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
|
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;
namespace DiscoBot.Audio
{
using DiscoBot.DSA_Game;
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);
}
SoundEffects.Play(tSound);
}
}
}
|