public static void DeleteAudio(AudioEntry audioToDelete) { try { File.Move(audioToDelete.Path, Path.Combine(ResDirectory, "trash", audioToDelete.FileName)); } catch (FileNotFoundException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{audioToDelete.Path} could not be found.The file has been removed from the database but please check that it has been deleted properly."); Console.ResetColor(); } AudioEntries.Remove(audioToDelete.Name); foreach (string alias in audioToDelete.Aliases) { Aliases.Remove(alias); } foreach (AudioCollection collection in AudioCollections.Values) { if (collection.AudioEntries.ContainsValue(audioToDelete)) { collection.AudioEntries.Remove(audioToDelete.Name); foreach (string alias in audioToDelete.Aliases) { collection.Aliases.Remove(alias); } } } }
public static void AddToUserIntros(ulong userId, AudioEntry audioEntry) { if (UserIntros.TryGetValue(userId, out List <AudioEntry> intros)) { intros.Add(audioEntry); } else { UserIntros.Add(userId, new List <AudioEntry>() { audioEntry }); } }
public static void AddToCollection(string collection, AudioEntry entry) { AudioCollections.TryGetValue(collection, out AudioCollection col); if (col == null) { AudioCollections[collection] = new AudioCollection(); col = AudioCollections[collection]; } col.AudioEntries.Add(entry.Name, entry); foreach (string alias in entry.Aliases) { col.Aliases.Add(alias, entry); } entry.Collections.Add(collection); }
public static void RemoveFromCollection(string collection, AudioEntry entry) { if (AudioCollections.TryGetValue(collection, out AudioCollection col)) { col.AudioEntries.Remove(entry.Name); foreach (string alias in entry.Aliases) { col.Aliases.Remove(alias); } entry.Collections.Remove(collection); } else { throw new CollectionNotFoundException(collection); } }
static async Task MainAsync() { discord = new DiscordClient(new DiscordConfiguration { Token = Environment.GetEnvironmentVariable("Bot_Token"), TokenType = TokenType.Bot, MinimumLogLevel = Microsoft.Extensions.Logging.LogLevel.Debug }); commands = discord.UseCommandsNext(new CommandsNextConfiguration { CaseSensitive = false, EnableDms = false, StringPrefixes = new string[] { "#", "$" } }); commands.RegisterCommands <MedicCommands>(); commands.CommandErrored += Commands_CommandErrored; commands.CommandExecuted += Commands_CommandExecuted; interactivity = discord.UseInteractivity(new InteractivityConfiguration { Timeout = TimeSpan.FromMinutes(1) }); // EnableIncoming = true increases CPU usage and is not being used until Speech Recognition can be handled easily. voice = discord.UseVoiceNext(new VoiceNextConfiguration { AudioFormat = new AudioFormat(48000, 2, VoiceApplication.LowLatency), EnableIncoming = false }); AudioHelper.Load(); AudioHelper.CheckForErrors(); System.Timers.Timer timer = new System.Timers.Timer(900000); // change this to a larger value later: 900000 timer.Elapsed += Timer_ElapsedAsync; timer.Enabled = true; if (!File.Exists("safe-guilds.txt")) { File.WriteAllText("safe-guilds.txt", "386570547267502080"); } discord.VoiceStateUpdated += async(client, e) => { if (voice.GetConnection(e.Guild) != null) //Remove(d) second check so bot can play audio for itself?? (&& e.User != discord.CurrentUser) { if (e.Channel == voice.GetConnection(e.Guild).TargetChannel&& !alreadyPlayedForUsers.Contains(e.User.Id)) { // If the user who triggered the event is in the same voice channel as the bot; AND the intro hasn't been played for the user yet List <AudioEntry> intros = AudioHelper.GetUniversalIntros(); List <AudioEntry> userIntros = AudioHelper.GetUserIntros(e.After.User.Id); if (userIntros != null || userIntros.Count != 0) // Exception here { intros.AddRange(userIntros); } AudioEntry introEntry = intros.OrderBy(e => new Random().Next()).First(); await Task.Delay(1000); await commands.ExecuteCommandAsync(commands.CreateFakeContext(e.User, e.Guild.Channels[505103389537992704], "#play " + introEntry.Name, "#", commands.RegisteredCommands["play"], introEntry.Name)); alreadyPlayedForUsers.Add(e.User.Id); } else if (e.Channel == null) { // Someone left alreadyPlayedForUsers.Remove(e.User.Id); if (e.Before.Channel.Users.Count() == 1) { await commands.ExecuteCommandAsync(commands.CreateFakeContext(e.User, e.Guild.Channels[505103389537992704], "#leave", "#", commands.RegisteredCommands["leave"])); } } } else if (e.User.Id == client.CurrentUser.Id) { // Bot did something if ((e.Before == null || e.Before.Channel == null) && (e.After != null && e.After.Channel != null)) { // Bot joined alreadyPlayedForUsers.AddRange(e.After.Channel.Users.Where(u => u.Id != client.CurrentUser.Id).Select(u => u.Id)); } else { // Bot left } } }; discord.MessageCreated += async(client, e) => { if (e.Author.Equals(discord.CurrentUser)) { return; } string messageContent = e.Message.Content.ToLower(); if (e.Author.Id == 477504775907311619 && e.Message.Content == "wrong" && discord.GetVoiceNext().GetConnection(e.Guild) != null) { DiscordUser medicUser = await discord.GetUserAsync(134336937224830977); //await commands.SudoAsync(medicUser, e.Channel, "#play wrong"); await commands.ExecuteCommandAsync(commands.CreateFakeContext(medicUser, e.Channel, "#play wrong", "#", commands.RegisteredCommands.Where(c => c.Key == "play").FirstOrDefault().Value, "wrong")); } else if (messageContent.StartsWith("creeper")) { await e.Channel.SendMessageAsync("Aww man!"); if (discord.GetVoiceNext().GetConnection(e.Guild) != null) { DiscordUser medicUser = await discord.GetUserAsync(134336937224830977); await commands.ExecuteCommandAsync(commands.CreateFakeContext(medicUser, e.Channel, "#play aw man", "#", commands.RegisteredCommands.Where(c => c.Key == "play").FirstOrDefault().Value, "aw man")); } } else if (messageContent.Contains("iftara") || messageContent.Contains("akşam ezanına")) { DateTime iftarTime = GetIftarTime(cityScheduleLinks.Keys.Where(s => messageContent.ToLower().Contains(s)).FirstOrDefault()); TimeSpan timeLeft = iftarTime.Subtract(DateTime.UtcNow.AddHours(3)); await e.Channel.SendMessageAsync("Akşam ezanı " + iftarTime.ToString("HH:mm") + " saatinde okunuyor, yani " + (timeLeft.Hours == 0 ? "" : timeLeft.Hours + " saat ") + timeLeft.Minutes + " dakika kaldı."); } else if (messageContent.Contains("sahura")) { DateTime imsakTime = GetImsakTime(cityScheduleLinks.Keys.Where(s => messageContent.ToLower().Contains(s)).FirstOrDefault()); TimeSpan timeLeft = imsakTime.Subtract(DateTime.UtcNow.AddHours(3)); await e.Channel.SendMessageAsync("İmsak " + imsakTime.ToString("HH:mm") + " saatinde, yani " + (timeLeft.Hours == 0 ? "" : timeLeft.Hours + " saat ") + timeLeft.Minutes + " dakika kaldı."); } else if (messageContent.Contains("okundu mu") || messageContent.Contains("kaçta oku")) { DateTime iftarTime = GetIftarTime(cityScheduleLinks.Keys.Where(s => messageContent.ToLower().Contains(s)).FirstOrDefault()); if (iftarTime.Day == DateTime.Today.Day) { TimeSpan timeLeft = iftarTime.Subtract(DateTime.UtcNow.AddHours(3)); await e.Channel.SendMessageAsync("Akşam ezanı " + iftarTime.ToString("HH:mm") + " saatinde okunuyor, yani " + (timeLeft.Hours == 0 ? "" : timeLeft.Hours + " saat ") + timeLeft.Minutes + " dakika kaldı."); } else { DateTime imsakTime = GetImsakTime(cityScheduleLinks.Keys.Where(s => messageContent.ToLower().Contains(s)).FirstOrDefault()); TimeSpan timeLeft = imsakTime.Subtract(DateTime.UtcNow.AddHours(3)); await e.Channel.SendMessageAsync("Okundu! Sahura " + (timeLeft.Hours == 0 ? "" : timeLeft.Hours + " saat ") + timeLeft.Minutes + " dakika kaldı."); } } else if (e.Message.Content.ToUpper().StartsWith("HOFFMAN")) { await e.Channel.SendMessageAsync("Yeah?"); var userReply = await interactivity.WaitForMessageAsync(m => m.Author.Id == e.Author.Id && m.Content.Contains(" call this"), TimeSpan.FromSeconds(5)); await e.Channel.SendMessageAsync("Uh, uhh..."); // TODO: Think of functionality for this HOFFMAN } }; HttpListener listener = new HttpListener(); if (!Debugger.IsAttached) { // In production listener.Prefixes.Add("http://*:3131/medicbotapi/"); } else { // Debugging listener.Prefixes.Add("http://127.0.0.1:3131/medicbotapi/"); } listener.Start(); _ = listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener); await discord.ConnectAsync(); await Task.Delay(-1); }
public static void RemoveFromUniversalIntros(AudioEntry audioEntry) { UniversalIntros.Remove(audioEntry); }
public static void AddToUniversalIntros(AudioEntry audioEntry) { UniversalIntros.Add(audioEntry); }
public static void RemoveFromUserIntros(ulong userId, AudioEntry audioEntry) { UserIntros[userId].Remove(audioEntry); }
public static void AddToAlias(string alias, AudioEntry entry) { Aliases[alias] = entry; }
public static void AddAudio(AudioEntry audioToAdd) { AudioEntries.Add(audioToAdd.Name, audioToAdd); }