summaryrefslogtreecommitdiff
path: root/DiscoBot
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-04-09 17:41:52 +0200
committerTrueDoctor <d-kobert@web.de>2018-04-09 17:41:52 +0200
commitbdd094926815196802c7d0bdad089fee9791abf4 (patch)
treeabfcafa5bf1463f5c8a94542018ba7c76a29a1be /DiscoBot
parentdb846b1eebf4ee35ea7f72024c0db753b73d0177 (diff)
Implemented Audio Memes small sound ques wich can be played from anywhere
Diffstat (limited to 'DiscoBot')
-rw-r--r--DiscoBot/Auxiliary/Soundeffects.cs54
-rw-r--r--DiscoBot/Auxiliary/SpellCorrect.cs2
-rw-r--r--DiscoBot/Characters/Character.cs12
-rw-r--r--DiscoBot/Commands/Voice.cs54
-rw-r--r--DiscoBot/DiscoBot.csproj1
5 files changed, 106 insertions, 17 deletions
diff --git a/DiscoBot/Auxiliary/Soundeffects.cs b/DiscoBot/Auxiliary/Soundeffects.cs
new file mode 100644
index 0000000..bc5bbb3
--- /dev/null
+++ b/DiscoBot/Auxiliary/Soundeffects.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DiscoBot.Auxiliary
+{
+ using DiscoBot.Commands;
+
+ public enum Sound
+ {
+ Ding,
+ Nooo,
+ Monterkill,
+ Finish,
+ Wrong
+ }
+
+ public static class SoundEffects
+ {
+ public static Task Play(Sound s)
+ {
+ string url = string.Empty;
+ int vol = 256;
+ switch (s)
+ {
+ case Sound.Ding:
+ url = "https://www.myinstants.com/media/sounds/boxing-bell.mp3";
+ break;
+ case Sound.Finish:
+ url = "https://www.myinstants.com/media/sounds/finishhim.swf.mp3";
+ break;
+ case Sound.Monterkill:
+ url = "https://www.myinstants.com/media/sounds/announcer_kill_monster_01.mp3";
+ break;
+ case Sound.Nooo:
+ url = "https://www.myinstants.com/media/sounds/nooo.swf.mp3";
+ break;
+ case Sound.Wrong:
+ url = "https://www.myinstants.com/media/sounds/stupid_dum_03.mp3";
+ vol = 10;
+ break;
+ }
+
+ if (url != string.Empty)
+ {
+ return Voice.SendAsync(url, vol);
+ }
+
+ return Dsa.GeneralContext.Channel.SendMessageAsync("Ton Existiert nicht");
+ }
+ }
+}
diff --git a/DiscoBot/Auxiliary/SpellCorrect.cs b/DiscoBot/Auxiliary/SpellCorrect.cs
index 1b740e8..244914b 100644
--- a/DiscoBot/Auxiliary/SpellCorrect.cs
+++ b/DiscoBot/Auxiliary/SpellCorrect.cs
@@ -6,6 +6,8 @@
public class SpellCorrect : StringComparer
{
+ public const int ErrorThreshold = 94100;
+
public override int Compare(string x, string y)
{
if (string.IsNullOrEmpty(x))
diff --git a/DiscoBot/Characters/Character.cs b/DiscoBot/Characters/Character.cs
index a78e613..249c6f5 100644
--- a/DiscoBot/Characters/Character.cs
+++ b/DiscoBot/Characters/Character.cs
@@ -71,8 +71,9 @@
var sc = new SpellCorrect();
var tTalent = this.Talente.OrderBy(x => sc.Compare(talent, x.Name)).First();
- if (sc.Compare(talent, tTalent.Name) > 94100)
+ if (sc.Compare(talent, tTalent.Name) > SpellCorrect.ErrorThreshold)
{
+ SoundEffects.Play(Sound.Wrong);
return $"{this.Name} kann nicht {talent}...";
}
@@ -164,8 +165,9 @@
var output = new StringBuilder();
var sc = new SpellCorrect();
var attack = this.Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First();
- if (sc.Compare(talent, attack.Name) > 94)
+ if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold)
{
+ SoundEffects.Play(Sound.Wrong);
return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen...";
}
@@ -187,8 +189,9 @@
var sc = new SpellCorrect();
var attack = this.Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First();
- if (sc.Compare(talent, attack.Name) > 94)
+ if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold)
{
+ SoundEffects.Play(Sound.Wrong);
return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen...";
}
@@ -210,8 +213,9 @@
var sc = new SpellCorrect();
int fk = this.Eigenschaften["fk"];
var attack = this.Talente.OrderBy(x => sc.Compare(talent, x.Name)).First();
- if (sc.Compare(talent, attack.Name) > 94)
+ if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold)
{
+ SoundEffects.Play(Sound.Wrong);
return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen...";
}
diff --git a/DiscoBot/Commands/Voice.cs b/DiscoBot/Commands/Voice.cs
index 772d807..3391452 100644
--- a/DiscoBot/Commands/Voice.cs
+++ b/DiscoBot/Commands/Voice.cs
@@ -1,8 +1,14 @@
namespace DiscoBot.Commands
{
+ using System;
+ using System.Collections.Generic;
using System.Diagnostics;
+ using System.Linq;
+ using System.Media;
using System.Threading.Tasks;
+ using DiscoBot.Auxiliary;
+
using Discord;
using Discord.Audio;
using Discord.Commands;
@@ -10,6 +16,17 @@
public class Voice : ModuleBase
{
public static IAudioClient Client { get; set; }
+
+ public static async Task SendAsync(string path, int volume = 256)
+ {
+ // Create FFmpeg using the previous example
+ var ffmpeg = CreateStream(path, volume);
+ var output = ffmpeg.StandardOutput.BaseStream;
+ var discord = Client.CreatePCMStream(AudioApplication.Music);
+ await output.CopyToAsync(discord);
+ await discord.FlushAsync();
+ }
+
[Command("join", RunMode = RunMode.Async)]
public async Task JoinChannelAsync(IVoiceChannel channel = null)
{
@@ -42,29 +59,40 @@
[Command("play")]
public Task PlayAudioAsync(string path)
{
- return Client == null ? this.Context.Channel.SendMessageAsync("Erst Joinen!") : SendAsync(path);
+ if (Client == null)
+ {
+ return this.Context.Channel.SendMessageAsync("Erst Joinen!");
+ }
+
+ 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(path, x.ToString())).First();
+
+ if (sc.Compare(path, tSound.ToString()) > SpellCorrect.ErrorThreshold)
+ {
+ return SendAsync(path);
+ }
+
+ return SoundEffects.Play(tSound);
}
- private static Process CreateStream(string path)
+ private static Process CreateStream(string path, int vol = 256)
{
var ffmpeg = new ProcessStartInfo
{
FileName = "ffmpeg",
- Arguments = $"-i {path} -ac 2 -f s16le -ar 48000 -ab 620000 pipe:1",
+ Arguments = $"-i {path} -ac 2 -f s16le -ar 48000 -ab 620000 -vol {vol} pipe:1",
UseShellExecute = false,
RedirectStandardOutput = true,
};
return Process.Start(ffmpeg);
}
-
- private static async Task SendAsync(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();
- }
}
}
diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj
index 3955ef6..29f4208 100644
--- a/DiscoBot/DiscoBot.csproj
+++ b/DiscoBot/DiscoBot.csproj
@@ -142,6 +142,7 @@
<ItemGroup>
<Compile Include="Auxiliary\Dice.cs" />
<Compile Include="Auxiliary\KampfTalent.cs" />
+ <Compile Include="Auxiliary\Soundeffects.cs" />
<Compile Include="Auxiliary\SpellCorrect.cs" />
<Compile Include="Auxiliary\Talent.cs" />
<Compile Include="Auxiliary\Vorteil.cs" />