public void Commands() { client.CommandPrefixes.Add("test."); client.AddCommand(DSharpPlus.Commands.DiscordCommand.Create("uinfo") .Do(async e => { string userInfo = $"```Fix{Environment.NewLine}Username: {e.Member.Username}{Environment.NewLine}Username: {e.Member.Username}{Environment.NewLine}```"; await e.Channel.SendMessageAsync(userInfo); }) ); client.AddCommand(DSharpPlus.Commands.DiscordCommand.Create("voice") .Do(async e => { try { DSharpPlus.Objects.DiscordChannel voiceChannel = client.GetChannelByID(226700492548472832); client.ConnectToVoiceChannel(voiceChannel, new DiscordVoiceConfig() { Channels = 2, FrameLengthMs = 60, OpusMode = DSharpPlus.Voice.OpusApplication.MusicOrMixed, SendOnly = false }, false, false); await e.Channel.SendMessageAsync($"Trying to connect"); } catch (Exception ex) { Console.WriteLine($"{ex.Message} ({ex.Source}): {Environment.NewLine}{ex.StackTrace}"); } }) ); client.AddCommand(DSharpPlus.Commands.DiscordCommand.Create("play") .Do(async e => { try { audio.SendAudioFile(e.Message.Content.Split(new char[] { ' ' })[1]); await e.Channel.SendMessageAsync($"Playing audiofile ``{e.Message.Content.Split(new char[] { ' ' })[1]}``"); } catch (Exception ex) { Console.WriteLine($"{ex.Message} ({ex.Source}): {Environment.NewLine}{ex.StackTrace}"); } }) ); }
void CreateCommands(DiscordClient _client) { _client.AddCommand("Travail", async(e) => { await e.Message.Parent.SendMessage("Wakhaaa a ouma inô!"); Console.WriteLine("Command Reveille toi"); while (!fini) { var watch = System.Diagnostics.Stopwatch.StartNew(); await job(); watch.Stop(); int t = (int)(30000 - watch.ElapsedMilliseconds); if (watch.ElapsedMilliseconds < 25000) { Console.WriteLine("Attende de " + t + " ms"); await Task.Delay(t); } else { Console.WriteLine("Pas d'attente"); } } }); _client.AddCommand("Ajoute", async(e) => { string reponse = "Joueur ajouté."; string ajout = e.Message.Content.Split(new string[] { "$Ajoute " }, StringSplitOptions.RemoveEmptyEntries)[0]; Console.WriteLine("Command Ajoute"); if (user.Contains(ajout)) { reponse = "Je l'espionne déjà."; } else { user.Add(ajout); } await e.Message.Parent.SendMessage(reponse); }); _client.AddCommand("Remove", async(e) => { string reponse = "C'est fait !"; string ajout = e.Message.Content.Split(new string[] { "$Remove " }, StringSplitOptions.RemoveEmptyEntries)[0]; Console.WriteLine("Command Remove"); if (user.Contains(ajout)) { user.Remove(ajout); } await e.Message.Parent.SendMessage(reponse); }); _client.AddCommand("Game", async(e) => { var watch = System.Diagnostics.Stopwatch.StartNew(); string reponse = ""; string requete = e.Message.Content; string[] split = requete.Split(new string[] { "$Game" }, StringSplitOptions.RemoveEmptyEntries); Console.WriteLine("Recherche de " + split[0] + "."); try { var summoner = api.GetSummoner(Region.euw, split[0]); var match = api.GetCurrentGame(Platform.EUW1, summoner.Id); var participants = match.Participants; List <string> sumId = new List <string>(); List <Summoner> sum = new List <Summoner>(); foreach (var item in participants) { sumId.Add(item.SummonerName); } sum = api.GetSummoners(Region.euw, sumId); Console.WriteLine("Début du formattage du KDA"); var lStats = statsByParticipants(participants, sum); Console.WriteLine("Fin du formattage du KDA"); var bans = match.BannedChampions; bans.Sort(delegate(BannedChampion x, BannedChampion y) { return(x.TeamId.CompareTo(y.TeamId)); }); string[] ban = { championByID(bans[0].ChampionId), championByID(bans[1].ChampionId), championByID(bans[2].ChampionId), championByID(bans[3].ChampionId), championByID(bans[4].ChampionId), championByID(bans[5].ChampionId) }; reponse = "```Red Team-- Bans[" + ban[0] + ", " + ban[1] + ", " + ban[2] + "]" + Environment.NewLine + Environment.NewLine; Console.WriteLine("Debut de recup du rang"); var l = rangBySummoner(participants, sum); Console.WriteLine("Fin de récup du rang"); int i = 0; IEnumerable <Tuple <string, string, string, string, string, string> > authors = new[] { Tuple.Create(participants[0].SummonerName, l[0], championByID(participants[0].ChampionId), lStats[i], spellByID(participants[0].SummonuerSpell1), spellByID(participants[0].SummonerSpell2)), Tuple.Create(participants[1].SummonerName, l[1], championByID(participants[1].ChampionId), lStats[i + 1], spellByID(participants[1].SummonuerSpell1), spellByID(participants[1].SummonerSpell2)), Tuple.Create(participants[2].SummonerName, l[2], championByID(participants[2].ChampionId), lStats[i + 2], spellByID(participants[2].SummonuerSpell1), spellByID(participants[2].SummonerSpell2)), Tuple.Create(participants[3].SummonerName, l[3], championByID(participants[3].ChampionId), lStats[i + 3], spellByID(participants[3].SummonuerSpell1), spellByID(participants[3].SummonerSpell2)), Tuple.Create(participants[4].SummonerName, l[4], championByID(participants[4].ChampionId), lStats[i + 4], spellByID(participants[4].SummonuerSpell1), spellByID(participants[4].SummonerSpell2)) }; reponse += authors.ToStringTable( new[] { "Pseudo", "Rang", "Champion", "KDA", "Spell 1", "Spell 2" }, a => a.Item1, a => a.Item2, a => a.Item3, a => a.Item4, a => a.Item5, a => a.Item6) + Environment.NewLine + Environment.NewLine; reponse += "Blue Team-- Bans[" + ban[3] + ", " + ban[4] + ", " + ban[5] + "]" + Environment.NewLine + Environment.NewLine; i = 5; authors = new[] { Tuple.Create(participants[5].SummonerName, l[i + 0], championByID(participants[5].ChampionId), lStats[i], spellByID(participants[5].SummonuerSpell1), spellByID(participants[5].SummonerSpell2)), Tuple.Create(participants[6].SummonerName, l[i + 1], championByID(participants[6].ChampionId), lStats[i + 1], spellByID(participants[6].SummonuerSpell1), spellByID(participants[6].SummonerSpell2)), Tuple.Create(participants[7].SummonerName, l[i + 2], championByID(participants[7].ChampionId), lStats[i + 2], spellByID(participants[7].SummonuerSpell1), spellByID(participants[7].SummonerSpell2)), Tuple.Create(participants[8].SummonerName, l[i + 3], championByID(participants[8].ChampionId), lStats[i + 3], spellByID(participants[8].SummonuerSpell1), spellByID(participants[8].SummonerSpell2)), Tuple.Create(participants[9].SummonerName, l[i + 4], championByID(participants[9].ChampionId), lStats[i + 4], spellByID(participants[9].SummonuerSpell1), spellByID(participants[9].SummonerSpell2)) }; reponse += authors.ToStringTable( new[] { "Pseudo", "Rang", "Champion", "KDA", "Spell 1", "Spell 2" }, a => a.Item1, a => a.Item2, a => a.Item3, a => a.Item4, a => a.Item5, a => a.Item6) + Environment.NewLine + "```"; } catch (RiotSharpException ex) { reponse = "Je trouve pas, désolé ptit frère ..."; Console.WriteLine(ex); } watch.Stop(); Console.WriteLine("La recherche a pris : " + watch.ElapsedMilliseconds + " ms"); await e.Message.Parent.SendMessage(reponse); }); }
public static void addcommands(DiscordClient p_discord) { p_discord.UseCommands(new CommandConfig { Prefix = "!", SelfBot = false, }); UserRepository userrepo = new UserRepository(new UserSQLContext()); MessageRepository msgrepo = new MessageRepository(new MessageSQLContext()); p_discord.AddCommand("hello", async e => { string[] msg = e.Message.Content.Split(' '); //if msg array contains more then 1 arrayobject then.. if (msg.Length > 1 && msg[1].Length >= 3) { bool ChannelContainsUser = false; List <DiscordUser> members = new List <DiscordUser>(); //check if member is in the current 'guild' foreach (DiscordMember dm in e.Guild.Members) { //check if msg[1] containst a part of the user if (dm.User.Username.ToUpper().Contains(msg[1].ToUpper())) { if (dm.User.Username.ToUpper() == msg[1].ToUpper()) { ChannelContainsUser = true; await e.Message.Respond($"{e.Message.Author.Username } says hello to <@{dm.User.ID}> "); break; } members.Add(dm.User); } if (members.Count > 1 && !ChannelContainsUser) { await e.Message.Respond($"more then 1 user with those characters in his name"); ChannelContainsUser = true; break; } } if (members.Count == 1) { ChannelContainsUser = true; await e.Message.Respond($"{e.Message.Author.Username } says hello to <@{members[0].ID}> "); } else if (!ChannelContainsUser) { await e.Message.Respond("That user is not in the current channel"); } } else { await e.Message.Respond($"Hello, {e.Message.Author.Mention}!"); } }); p_discord.AddCommand("reken", async e => { string[] msg = e.Message.Content.Split(' '); try { double num1 = Convert.ToDouble(msg[1]); double num2 = Convert.ToDouble(msg[3]); double num3 = 1; if (msg.Length > 4) { num3 = Convert.ToDouble(msg[4]); } switch (msg[2]) { case "+": await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 + num2).ToString()); break; case "-": await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 - num2).ToString()); break; case "*": case "x": await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 * num2).ToString()); break; case "/": await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 / num2).ToString()); break; case "**": case "^": await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + Math.Pow(num1, num2).ToString()); break; case "^^": await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + Math.Pow(Math.Pow(num1, num2), num3).ToString()); break; case "%": await e.Message.Respond(num1.ToString() + msg[2] + num2.ToString() + '=' + (num1 % num2).ToString()); break; case ">": case "<": case "==": case "!=": await e.Message.Respond(msg[1] + " " + msg[2] + " " + msg[3] + " " + "= " + Operator(msg[2], num1, num2).ToString()); break; default: break; } } catch (Exception exc) { await e.Message.Respond(exc.Message); } }); p_discord.AddCommand("join", async e => { try { var vcfg = new VoiceNextConfiguration { VoiceApplication = DSharpPlus.VoiceNext.Codec.VoiceApplication.Music }; VoiceService = p_discord.UseVoiceNext(vcfg); await VoiceService.ConnectAsync(await p_discord.GetChannelByID(272324215439491072)); Console.WriteLine("Joined voice channel"); } catch (Exception exc) { Console.WriteLine(exc.Message); } }); p_discord.AddCommand("dc", async e => { try { DiscordGuild guild = await p_discord.GetGuild(e.Channel.GuildID); VoiceService.GetConnection(guild).Disconnect(); VoiceService.GetConnection(guild).Dispose(); } catch (Exception exc) { Console.WriteLine(exc.Message); } }); p_discord.AddCommand("god", async e => { if (e.Message.Author.ID == 261216517910167554) { await e.Message.Respond("AND THE REAL C#GOD IS....\n" + e.Message.Author.Username); } else { await e.Message.Respond("you're not teh real c#god."); } }); p_discord.AddCommand("kkk", async e => { await e.Message.Respond($"WHITE POWER, RIGHT { e.Message.Author.Username }?"); }); p_discord.AddCommand("help", async e => { string prefix = "!"; await e.Message.Respond($"currently available commands are: \n{prefix}hello <username> \n{prefix}reken 'nummer' 'operator' 'nummer' \n{prefix}god to see if you are a c# god\n{prefix}karma @username to give a user karma!\n" + $"{prefix}dice 'minimumnumber' 'maximumnumber' (without the quotes) to generate a random number. {prefix}dice will automatically pick a number between 1 and 100.\n" + $"\n\nThis bot also functions as Robot9000. This means that the bot will mute you if you post duplicate content that already has been posted in this server.\n" + "The amount of time you get muted depends on the amount of punishments you already had."); }); p_discord.AddCommand("666", async e => { await e.Message.Respond("HAIL SATAN " + e.Message.Author.Username); }); p_discord.AddCommand("blm", async e => { await e.Message.Respond("BLACK HAS NO POWER, RIGHT " + e.Message.Author.Username + "?"); }); p_discord.AddCommand("play", async e => { try { DiscordGuild guild = await p_discord.GetGuild(e.Channel.GuildID); var rand = new Random(); var bytes = new byte[32000]; rand.NextBytes(bytes); await VoiceService.GetConnection(guild).SendAsync(bytes, 517, 16); Console.Write("i just played something!"); } catch (Exception exc) { Console.WriteLine(exc.Message); } }); p_discord.AddCommand("karma", async e => { string[] msg = e.Message.Content.Split(' '); List <DiscordUser> users = e.Message.Mentions; if (users.Count == 1) { if (users[0].ID != e.Message.Author.ID) { int karma = AddKarma(users[0].ID); await e.Message.Respond($"{users[0].Username} gained 1 karma!\n{users[0].Username} now has {karma} karma"); } else { await e.Message.Respond($"You just lost 1 karma"); } } else if (users.Count > 1) { await e.Message.Respond($"Please only mention 1 user :)"); } else { await e.Message.Respond($"You have to at least mention 1 user"); } }); p_discord.AddCommand("dice", async e => { string[] msg = e.Message.Content.Split(' '); if (msg.Length > 1) { int random = Dice(Convert.ToInt32(msg[1]), Convert.ToInt32(msg[2])); await e.Message.Respond(random.ToString()); } else if (msg.Length == 1) { int random = Dice(1, 101); await e.Message.Respond(random.ToString()); } else { await e.Message.Respond("Please use 2 parameters divided by a space"); } }); p_discord.AddCommand("unmute", async e => { await Task.Delay(0); if (e.Message.Author.ID == 261216517910167554 || e.Message.Author.ID == 239471183475638272) { if (e.Message.Mentions.Count > 0) { foreach (DiscordUser user in e.Message.Mentions) { new UserRepository(new UserSQLContext()).Unmute(user.ID); await e.Message.Respond($"{e.Message.Author.Username } unmuted <@{user.ID}> "); } } else { await e.Message.Respond($"Please mention the user(s) you want to unmute!"); } } else { await e.Message.Respond($"You ar not permitted to unmute users!"); } }); p_discord.AddCommand("mutereset", async e => { if (e.Message.Author.ID == 261216517910167554 || e.Message.Author.ID == 239471183475638272) { if (userrepo.MuteCountreset()) { userrepo.MuteReset(); await e.Message.Respond("Robot9000 mutes have been reset!"); } else { await e.Message.Respond("Oops! looks like something went wrong. Please contact Mivo90"); } } else { await e.Message.Respond("I'm sorry, I can not let you do that."); } }); p_discord.AddCommand("messagereset", async e => { if (e.Message.Author.ID == 261216517910167554 || e.Message.Author.ID == 239471183475638272) { if (msgrepo.ResetMessages()) { await e.Message.Respond("Robot9000 messages have been reset!"); } else { await e.Message.Respond("Oops, couldn't reset the messages. Please contact Mivo90"); } } else { await e.Message.Respond("Nice try."); } }); }