internal override void Init(CommandGroupBuilder cgb) { cgb.CreateCommand(Module.Prefix + "typestart") .Description($"Startet einen Tipp-Wettbewerb. | `{Prefix}typestart`") .Do(DoFunc()); cgb.CreateCommand(Module.Prefix + "typestop") .Description($"Stoppt einen Tipp-Wettbewerb auf dem derzeitigen Channel. | `{Prefix}typestop`") .Do(QuitFunc()); cgb.CreateCommand(Module.Prefix + "typeadd") .Description($"Fügt einen neuen Text hinzu. Owner only. | `{Prefix}typeadd wordswords`") .Parameter("text", ParameterType.Unparsed) .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id) || string.IsNullOrWhiteSpace(e.GetArg("text"))) { return; } DbHandler.Instance.Connection.Insert(new TypingArticle { Text = e.GetArg("text"), DateAdded = DateTime.Now }); await e.Channel.SendMessage("Neuer Text hinzugefügt.").ConfigureAwait(false); }); }
public override void Install(ModuleManager manager) { var rng = new Random(); manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); cgb.CreateCommand("..") .Description("Fügt ein neues Zitat mit Keyword (einzelnes Wort) und Nachricht (kein Limit). | `.. abc My message`") .Parameter("keyword", ParameterType.Required) .Parameter("text", ParameterType.Unparsed) .Do(async e => { var text = e.GetArg("text"); if (string.IsNullOrWhiteSpace(text)) { return; } await Task.Run(() => Classes.DbHandler.Instance.Connection.Insert(new DataModels.UserQuote() { DateAdded = DateTime.Now, Keyword = e.GetArg("keyword").ToLowerInvariant(), Text = text, UserName = e.User.Name, })).ConfigureAwait(false); await e.Channel.SendMessage("`Neues Zitat hinzugefügt.`").ConfigureAwait(false); }); cgb.CreateCommand("...") .Description("Zeigt ein zufälliges Zitat eines Benutzers. | `... abc`") .Parameter("keyword", ParameterType.Required) .Do(async e => { var keyword = e.GetArg("keyword")?.ToLowerInvariant(); if (string.IsNullOrWhiteSpace(keyword)) { return; } var quote = Classes.DbHandler.Instance.GetRandom <UserQuote> ( uqm => uqm.Keyword == keyword); if (quote != null) { await e.Channel.SendMessage($"📣 {quote.Text}").ConfigureAwait(false); } else { await e.Channel.SendMessage("💢`Kein Zitat gefunden.`").ConfigureAwait(false); } }); cgb.CreateCommand("..qdel") .Alias("..quotedelete") .Description("Löscht alle Zitate mit angegebenen Keyword. Du musst entweder der Bot-Besitzer oder der Ersteller des Quotes sein um es zu löschen. | `..qdel abc`") .Parameter("quote", ParameterType.Required) .Do(async e => { var text = e.GetArg("quote")?.Trim(); if (string.IsNullOrWhiteSpace(text)) { return; } await Task.Run(() => { if (MidnightBot.IsOwner(e.User.Id)) { Classes.DbHandler.Instance.DeleteWhere <UserQuote> (uq => uq.Keyword == text); } else { Classes.DbHandler.Instance.DeleteWhere <UserQuote> (uq => uq.Keyword == text && uq.UserName == e.User.Name || uq.Keyword == e.User.Name.ToLowerInvariant()); } }).ConfigureAwait(false); await e.Channel.SendMessage("`Erledigt.`").ConfigureAwait(false); }); cgb.CreateCommand("..qdelothers") .Alias("..quotedeleteothers") .Description("Löscht alle Zitate mit eigenem Namen als Keyword, welche von anderen geaddet wurden. | `..qdelothers`") .Do(async e => { var text = e.User.Name.ToLowerInvariant(); await Task.Run(() => { Classes.DbHandler.Instance.DeleteWhere <UserQuote> (uq => uq.Keyword == text && uq.UserName != e.User.Name); }).ConfigureAwait(false); await e.Channel.SendMessage("`Erledigt.`").ConfigureAwait(false); }); cgb.CreateCommand("..qshow") .Description("Zeigt alle Zitate mit angegebenen Keyword. | `..qshow abc`") .Parameter("quote", ParameterType.Required) .Do(async e => { var text = e.GetArg("quote")?.Trim(); var allQuotes = ""; var number = 1; if (string.IsNullOrWhiteSpace(text)) { return; } await Task.Run(() => { var quoteList = Classes.DbHandler.Instance.FindAll <UserQuote> (uq => uq.Keyword == text); foreach (UserQuote quote in quoteList) { allQuotes += $"{number}. `{quote.Text}` **Hinzugefügt von: {quote.UserName}**\n"; number++; } }).ConfigureAwait(false); await e.Channel.SendMessage(allQuotes).ConfigureAwait(false); }); }); manager.CreateCommands(MidnightBot.BotMention, cgb => { var client = manager.Client; cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(cmd => cmd.Init(cgb)); cgb.CreateCommand("die") .Description($"Funktioniert nur für den Owner. Fährt den Bot herunter. | `@{BotName} die`") .Do(async e => { if (MidnightBot.IsOwner(e.User.Id)) { await e.Channel.SendMessage(e.User.Mention + ", Alles klar Chef.").ConfigureAwait(false); await Task.Delay(5000).ConfigureAwait(false); Environment.Exit(0); } else { await e.Channel.SendMessage(e.User.Mention + ", Nein."); } }); var randServerSw = new Stopwatch(); randServerSw.Start(); cgb.CreateCommand("do you love me") .Alias("do you love me?") .Description($"Antwortet nur dem Owner positiv. | `@{BotName} do you love me`") .Do(async e => { if (MidnightBot.IsOwner(e.User.Id)) { await e.Channel.SendMessage(e.User.Mention + ", Aber natürlich tue ich das. <3").ConfigureAwait(false); } else { await e.Channel.SendMessage(e.User.Mention + ", Sei doch nicht dumm. :P").ConfigureAwait(false); } }); cgb.CreateCommand("how are you") .Alias("how are you?") .Description($"Antwortet nur positiv, wenn der Owner online ist. | `@{BotName} do you love me`") .Do(async e => { if (MidnightBot.IsOwner(e.User.Id)) { await e.Channel.SendMessage(e.User.Mention + " Mir geht es gut, solange du da bist.").ConfigureAwait(false); return; } var kw = e.Server.GetUser(MidnightBot.Creds.OwnerIds[0]); if (kw != null && kw.Status == UserStatus.Online) { await e.Channel.SendMessage(e.User.Mention + " Mir geht es gut, solange " + kw.Mention + " hier mit mir ist.").ConfigureAwait(false); } else { await e.Channel.SendMessage(e.User.Mention + " Ich bin traurig. Mein Meister ist nicht hier.").ConfigureAwait(false); } }); cgb.CreateCommand("insult") .Parameter("mention", ParameterType.Required) .Description($"Beleidigt @X Person. | @{BotName} insult @X.") .Do(async e => { var u = e.Channel.FindUsers(e.GetArg("mention")).FirstOrDefault(); if (u == null) { await e.Channel.SendMessage("Ungültiger Benutzer.").ConfigureAwait(false); return; } if (MidnightBot.IsOwner(u.Id)) { await e.Channel.SendMessage("Ich würde nie meinen Meister beleidigen. <3").ConfigureAwait(false); return; } else if (u.Id == e.User.Id) { await e.Channel.SendMessage("Man muss schon doof sein, wenn man sich selber beleidigen will.") .ConfigureAwait(false); return; } else if (u.Id == MidnightBot.Client.CurrentUser.Id) { await e.Channel.SendMessage(e.User.Mention + " Denkst du wirklich ich beleidige mich selbst, du Schwachkopf. :P") .ConfigureAwait(false); return; } else { tester = 0; //var msgs = (await e.Channel.DownloadMessages (100)).Where (m => m.User.Id == MidnightBot.client.CurrentUser.Id); foreach (var m in (await e.Channel.DownloadMessages(10)).Where(m => m.User.Id == e.User.Id)) { if (tester == 0) { await m.Delete(); tester++; } } await e.Channel.SendMessage(u.Mention + MidnightBot.Locale.Insults[rng.Next(0, MidnightBot.Locale.Insults.Length)]) .ConfigureAwait(false); } }); cgb.CreateCommand("praise") .Description($"Lobt @X Person. | @{BotName} praise @X.") .Parameter("mention", ParameterType.Required) .Do(async e => { var u = e.Channel.FindUsers(e.GetArg("mention")).FirstOrDefault(); if (u == null) { await e.Channel.SendMessage("Ungültiger Benutzer.").ConfigureAwait(false); return; } if (MidnightBot.IsOwner(u.Id)) { await e.Channel.SendMessage(e.User.Mention + " Ich brauche deine Erlaubnis nicht, um meinen Meister zu loben <3") .ConfigureAwait(false); return; } else if (u.Id == e.User.Id) { await e.Channel.SendMessage($"Eigenlob stinkt {e.User.Mention}") .ConfigureAwait(false); return; } else { await e.Channel.SendMessage(u.Mention + MidnightBot.Locale.Praises[rng.Next(0, MidnightBot.Locale.Praises.Length)]) .ConfigureAwait(false); } }); cgb.CreateCommand("fire") .Description($"Zeigt eine unicode Feuer Nachricht. Optionaler Parameter [x] sagt ihm wie oft er das Feuer wiederholen soll. | `@{BotName} fire [x]`") .Parameter("times", ParameterType.Optional) .Do(async e => { int count; if (string.IsNullOrWhiteSpace(e.Args[0])) { count = 1; } else { int.TryParse(e.Args[0], out count); } if (count < 1 || count > 12) { await e.Channel.SendMessage("Nummer muss zwischen 1 und 12 sein.").ConfigureAwait(false); return; } var str = new StringBuilder(); for (var i = 0; i < count; i++) { str.Append(firestr); } await e.Channel.SendMessage(str.ToString()).ConfigureAwait(false); }); cgb.CreateCommand("dump") .Description($"Dumped alle Einladungen die er findet in dump.txt.** Owner Only.** | `@{BotName} dump`") .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id)) { return; } var i = 0; var j = 0; var invites = ""; foreach (var s in client.Servers) { try { var invite = await s.CreateInvite(0).ConfigureAwait(false); invites += invite.Url + "\n"; i++; } catch { j++; continue; } } File.WriteAllText("dump.txt", invites); await e.Channel.SendMessage($"Ich habe Einladungen für {i} Server bekommen und konnte für {j} Server keine Einladungen finden.") .ConfigureAwait(false); }); cgb.CreateCommand("ab") .Description($"Versuche 'abalabahaha' zu bekommen.| `@{BotName} ab`") .Do(async e => { string[] strings = { "ba", "la", "ha" }; var construct = "@a"; var cnt = rng.Next(4, 7); while (cnt-- > 0) { construct += strings[rng.Next(0, strings.Length)]; } await e.Channel.SendMessage(construct).ConfigureAwait(false); }); }); }
public override void Install(ModuleManager manager) { var client = MidnightBot.Client; manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(cmd => cmd.Init(cgb)); cgb.CreateCommand(Prefix + "next") .Alias(Prefix + "n") .Alias(Prefix + "skip") .Description($"Goes to the next song in the queue. You have to be in the same voice channel as the bot. | `{Prefix}n`") .Do(e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (musicPlayer.PlaybackVoiceChannel == e.User.VoiceChannel) { musicPlayer.Next(); } }); cgb.CreateCommand(Prefix + "stop") .Alias(Prefix + "s") .Description($"Stops the music and clears the playlist. Stays in the channel. | `{Prefix}s`") .Do(e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel == musicPlayer.PlaybackVoiceChannel) { musicPlayer.Autoplay = false; musicPlayer.Stop(); } }); cgb.CreateCommand(Prefix + "destroy") .Alias(Prefix + "d") .Description("Completely stops the music and unbinds the bot from the channel. " + $"(may cause weird behaviour) | `{Prefix}d`") .Do(e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryRemove(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel == musicPlayer.PlaybackVoiceChannel) { musicPlayer.Destroy(); } }); cgb.CreateCommand(Prefix + "pause") .Alias(Prefix + "p") .Description($"Pauses or Unpauses the song. | `{Prefix}p`") .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel != musicPlayer.PlaybackVoiceChannel) { return; } musicPlayer.TogglePause(); if (musicPlayer.Paused) { await e.Channel.SendMessage("🎵`Music Player paused.`").ConfigureAwait(false); } else { await e.Channel.SendMessage("🎵`Music Player unpaused.`").ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "queue") .Alias(Prefix + "q") .Alias(Prefix + "yq") .Description("Queue a song using keywords or a link. Bot will join your voice channel." + $"**You must be in a voice channel**. | `{Prefix}q Dream Of Venice`") .Parameter("query", ParameterType.Unparsed) .Do(async e => { await QueueSong(e.User, e.Channel, e.User.VoiceChannel, e.GetArg("query")).ConfigureAwait(false); if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages) { await Task.Delay(10000).ConfigureAwait(false); await e.Message.Delete().ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "soundcloudqueue") .Alias(Prefix + "sq") .Description("Queue a soundcloud song using keywords. Bot will join your voice channel." + $"**You must be in a voice channel**. | `{Prefix}sq Dream Of Venice`") .Parameter("query", ParameterType.Unparsed) .Do(async e => { await QueueSong(e.User, e.Channel, e.User.VoiceChannel, e.GetArg("query"), musicType: MusicType.Soundcloud).ConfigureAwait(false); if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages) { await Task.Delay(10000).ConfigureAwait(false); await e.Message.Delete().ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "listqueue") .Alias(Prefix + "lq") .Description($"Lists 15 currently queued songs per page. Default page is 1. | `{Prefix}lq` or `{Prefix}lq 2`") .Parameter("page", ParameterType.Optional) .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { await e.Channel.SendMessage("🎵 No active music player.").ConfigureAwait(false); return; } int page; if (!int.TryParse(e.GetArg("page"), out page) || page <= 0) { page = 1; } var currentSong = musicPlayer.CurrentSong; if (currentSong == null) { return; } var toSend = $"🎵`Now Playing` {currentSong.PrettyName} " + $"{currentSong.PrettyCurrentTime()}\n"; if (musicPlayer.RepeatSong) { toSend += "🔂"; } else if (musicPlayer.RepeatPlaylist) { toSend += "🔁"; } toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` "; if (musicPlayer.MaxQueueSize != 0 && musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize) { toSend += "**Song queue is full!**\n"; } else { toSend += "\n"; } const int itemsPerPage = 15; int startAt = itemsPerPage * (page - 1); var number = 1 + startAt; await e.Channel.SendMessage(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "nowplaying") .Alias(Prefix + "np") .Description($"Shows the song currently playing. | `{Prefix}np`") .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } var currentSong = musicPlayer.CurrentSong; if (currentSong == null) { return; } await e.Channel.SendMessage($"🎵`Now Playing` {currentSong.PrettyName} " + $"{currentSong.PrettyCurrentTime()}").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "volume") .Alias(Prefix + "vol") .Description($"Sets the music volume 0-100% | `{Prefix}vol 50`") .Parameter("val", ParameterType.Required) .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel != musicPlayer.PlaybackVoiceChannel) { return; } var arg = e.GetArg("val"); int volume; if (!int.TryParse(arg, out volume)) { await e.Channel.SendMessage("Volume number invalid.").ConfigureAwait(false); return; } volume = musicPlayer.SetVolume(volume); await e.Channel.SendMessage($"🎵 `Volume set to {volume}%`").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "defvol") .Alias(Prefix + "dv") .Description("Sets the default music volume when music playback is started (0-100)." + $" Persists through restarts. | `{Prefix}dv 80`") .Parameter("val", ParameterType.Required) .Do(async e => { var arg = e.GetArg("val"); float volume; if (!float.TryParse(arg, out volume) || volume < 0 || volume > 100) { await e.Channel.SendMessage("Volume number invalid.").ConfigureAwait(false); return; } var conf = SpecificConfigurations.Default.Of(e.Server.Id); conf.DefaultMusicVolume = volume / 100; await e.Channel.SendMessage($"🎵 `Default volume set to {volume}%`").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "mute") .Alias(Prefix + "min") .Description($"Sets the music volume to 0% | `{Prefix}min`") .Do(e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel != musicPlayer.PlaybackVoiceChannel) { return; } musicPlayer.SetVolume(0); }); cgb.CreateCommand(Prefix + "max") .Description($"Sets the music volume to 100%. | `{Prefix}max`") .Do(e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel != musicPlayer.PlaybackVoiceChannel) { return; } musicPlayer.SetVolume(100); }); cgb.CreateCommand(Prefix + "half") .Description($"Sets the music volume to 50%. | `{Prefix}half`") .Do(e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel != musicPlayer.PlaybackVoiceChannel) { return; } musicPlayer.SetVolume(50); }); cgb.CreateCommand(Prefix + "shuffle") .Alias(Prefix + "sh") .Description($"Shuffles the current playlist. | `{Prefix}sh`") .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel != musicPlayer.PlaybackVoiceChannel) { return; } if (musicPlayer.Playlist.Count < 2) { await e.Channel.SendMessage("💢 Not enough songs in order to perform the shuffle.").ConfigureAwait(false); return; } musicPlayer.Shuffle(); await e.Channel.SendMessage("🎵 `Songs shuffled.`").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "playlist") .Alias(Prefix + "pl") .Description($"Queues up to 500 songs from a youtube playlist specified by a link, or keywords. | `{Prefix}pl playlist link or name`") .Parameter("playlist", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("playlist"); if (string.IsNullOrWhiteSpace(arg)) { return; } if (e.User.VoiceChannel?.Server != e.Server) { await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); return; } var plId = await SearchHelper.GetPlaylistIdByKeyword(arg).ConfigureAwait(false); if (plId == null) { await e.Channel.SendMessage("No search results for that query."); return; } var ids = await SearchHelper.GetVideoIDs(plId, 500).ConfigureAwait(false); if (ids == null || ids.Count == 0) { await e.Channel.SendMessage($"🎵 `Failed to find any songs.`").ConfigureAwait(false); return; } var idArray = ids as string[] ?? ids.ToArray(); var count = idArray.Length; var msg = await e.Channel.SendMessage($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`").ConfigureAwait(false); foreach (var id in idArray) { try { await QueueSong(e.User, e.Channel, e.User.VoiceChannel, id, true).ConfigureAwait(false); } catch (PlaylistFullException) { break; } catch { } } await msg.Edit("🎵 `Playlist queue complete.`").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "soundcloudpl") .Alias(Prefix + "scpl") .Description($"Queue a soundcloud playlist using a link. | `{Prefix}scpl https://soundcloud.com/saratology/sets/symphony`") .Parameter("pl", ParameterType.Unparsed) .Do(async e => { var pl = e.GetArg("pl")?.Trim(); if (string.IsNullOrWhiteSpace(pl)) { return; } var scvids = JObject.Parse(await SearchHelper.GetResponseStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={MidnightBot.Creds.SoundCloudClientID}").ConfigureAwait(false))["tracks"].ToObject <SoundCloudVideo[]>(); await QueueSong(e.User, e.Channel, e.User.VoiceChannel, scvids[0].TrackLink).ConfigureAwait(false); MusicPlayer mp; if (!MusicPlayers.TryGetValue(e.Server, out mp)) { return; } foreach (var svideo in scvids.Skip(1)) { try { mp.AddSong(new Song(new Classes.SongInfo { Title = svideo.FullName, Provider = "SoundCloud", Uri = svideo.StreamLink, ProviderType = MusicType.Normal, Query = svideo.TrackLink, }), e.User.Name); } catch (PlaylistFullException) { break; } } }); cgb.CreateCommand(Prefix + "localplaylst") .Alias(Prefix + "lopl") .Description($"Queues all songs from a directory. **Bot Owner Only!** | `{Prefix}lopl C:/music/classical`") .Parameter("directory", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { var arg = e.GetArg("directory"); if (string.IsNullOrWhiteSpace(arg)) { return; } try { var fileEnum = new DirectoryInfo(arg).GetFiles() .Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)); foreach (var file in fileEnum) { try { await QueueSong(e.User, e.Channel, e.User.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false); } catch (PlaylistFullException) { break; } catch { } } await e.Channel.SendMessage("🎵 `Directory queue complete.`").ConfigureAwait(false); } catch { } }); cgb.CreateCommand(Prefix + "radio").Alias(Prefix + "ra") .Description($"Queues a radio stream from a link. It can be a direct mp3 radio stream, .m3u, .pls .asx or .xspf (Usage Video: <https://streamable.com/al54>) | `{Prefix}ra radio link here`") .Parameter("radio_link", ParameterType.Required) .Do(async e => { if (e.User.VoiceChannel?.Server != e.Server) { await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); return; } await QueueSong(e.User, e.Channel, e.User.VoiceChannel, e.GetArg("radio_link"), musicType: MusicType.Radio).ConfigureAwait(false); if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages) { await Task.Delay(10000).ConfigureAwait(false); await e.Message.Delete().ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "local") .Alias(Prefix + "lo") .Description($"Queues a local file by specifying a full path. **Bot Owner Only!** | `{Prefix}lo C:/music/mysong.mp3`") .Parameter("path", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { var arg = e.GetArg("path"); if (string.IsNullOrWhiteSpace(arg)) { return; } await QueueSong(e.User, e.Channel, e.User.VoiceChannel, e.GetArg("path"), musicType: MusicType.Local).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "move") .Alias(Prefix + "mv") .Description($"Moves the bot to your voice channel. (works only if music is already playing) | `{Prefix}mv`") .Do(e => { MusicPlayer musicPlayer; var voiceChannel = e.User.VoiceChannel; if (voiceChannel == null || voiceChannel.Server != e.Server || !MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } musicPlayer.MoveToVoiceChannel(voiceChannel); }); cgb.CreateCommand(Prefix + "remove") .Alias(Prefix + "rm") .Description($"Remove a song by its # in the queue, or 'all' to remove whole queue. | `{Prefix}rm 5`") .Parameter("num", ParameterType.Required) .Do(async e => { var arg = e.GetArg("num"); MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel != musicPlayer.PlaybackVoiceChannel) { return; } if (arg?.ToLower() == "all") { musicPlayer.ClearQueue(); await e.Channel.SendMessage($"🎵`Queue cleared!`").ConfigureAwait(false); return; } int num; if (!int.TryParse(arg, out num)) { return; } if (num <= 0 || num > musicPlayer.Playlist.Count) { return; } var song = (musicPlayer.Playlist as List <Song>)?[num - 1]; musicPlayer.RemoveSongAt(num - 1); await e.Channel.SendMessage($"🎵**Track {song.PrettyName} at position `#{num}` has been removed.**").ConfigureAwait(false); }); //var msRegex = new Regex(@"(?<n1>\d+)>(?<n2>\d+)", RegexOptions.Compiled); cgb.CreateCommand(Prefix + "movesong") .Alias(Prefix + "ms") .Description($"Moves a song from one position to another. | `{Prefix} ms` 5>3") .Parameter("fromto") .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } var fromto = e.GetArg("fromto").Trim(); var fromtoArr = fromto.Split('>'); int n1; int n2; var playlist = musicPlayer.Playlist as List <Song> ?? musicPlayer.Playlist.ToList(); if (fromtoArr.Length != 2 || !int.TryParse(fromtoArr[0], out n1) || !int.TryParse(fromtoArr[1], out n2) || n1 <1 || n2 <1 || n1 == n2 || n1> playlist.Count || n2> playlist.Count) { await e.Channel.SendMessage("`Invalid input.`").ConfigureAwait(false); return; } var s = playlist[n1 - 1]; playlist.Insert(n2 - 1, s); var nn1 = n2 < n1 ? n1 : n1 - 1; playlist.RemoveAt(nn1); await e.Channel.SendMessage($"🎵`Moved` {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "setmaxqueue") .Alias(Prefix + "smq") .Description($"Sets a maximum queue size. Supply 0 or no argument to have no limit. | `{Prefix}smq` 50 or `{Prefix}smq`") .Parameter("size", ParameterType.Unparsed) .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } var sizeStr = e.GetArg("size")?.Trim(); uint size = 0; if (string.IsNullOrWhiteSpace(sizeStr) || !uint.TryParse(sizeStr, out size)) { size = 0; } musicPlayer.MaxQueueSize = size; await e.Channel.SendMessage($"🎵 `Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}`"); }); cgb.CreateCommand(Prefix + "cleanup") .Description($"Cleans up hanging voice connections. **Bot Owner Only!** | `{Prefix}cleanup`") .AddCheck(SimpleCheckers.OwnerOnly()) .Do(e => { foreach (var kvp in MusicPlayers) { var songs = kvp.Value.Playlist; var currentSong = kvp.Value.CurrentSong; if (songs.Count == 0 && currentSong == null) { MusicPlayer throwaway; MusicPlayers.TryRemove(kvp.Key, out throwaway); throwaway.Destroy(); } } }); cgb.CreateCommand(Prefix + "reptcursong") .Alias(Prefix + "rcs") .Description($"Toggles repeat of current song. | `{Prefix}rcs`") .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } var currentSong = musicPlayer.CurrentSong; if (currentSong == null) { return; } var currentValue = musicPlayer.ToggleRepeatSong(); await e.Channel.SendMessage(currentValue ? $"🎵🔂`Repeating track:`{currentSong.PrettyName}" : $"🎵🔂`Current track repeat stopped.`") .ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "rpeatplaylst") .Alias(Prefix + "rpl") .Description($"Toggles repeat of all songs in the queue (every song that finishes is added to the end of the queue). | `{Prefix}rpl`") .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } var currentValue = musicPlayer.ToggleRepeatPlaylist(); await e.Channel.SendMessage($"🎵🔁`Repeat playlist {(currentValue ? "enabled" : "disabled")}`").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "save") .Description($"Saves a playlist under a certain name. Name must be no longer than 20 characters and mustn't contain dashes. | `{Prefix}save classical1`") .Parameter("name", ParameterType.Unparsed) .Do(async e => { var name = e.GetArg("name")?.Trim(); if (string.IsNullOrWhiteSpace(name) || name.Length > 20 || name.Contains("-")) { return; } MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } //to avoid concurrency issues var currentPlaylist = new List <Song>(musicPlayer.Playlist); var curSong = musicPlayer.CurrentSong; if (curSong != null) { currentPlaylist.Insert(0, curSong); } if (!currentPlaylist.Any()) { return; } var songInfos = currentPlaylist.Select(s => new DataModels.SongInfo { Provider = s.SongInfo.Provider, ProviderType = (int)s.SongInfo.ProviderType, Title = s.SongInfo.Title, Uri = s.SongInfo.Uri, Query = s.SongInfo.Query, }).ToList(); var playlist = new MusicPlaylist { CreatorId = (long)e.User.Id, CreatorName = e.User.Name, Name = name.ToLowerInvariant(), }; DbHandler.Instance.SaveAll(songInfos); DbHandler.Instance.Save(playlist); DbHandler.Instance.Connection.InsertAll(songInfos.Select(s => new PlaylistSongInfo { PlaylistId = playlist.Id.Value, SongInfoId = s.Id.Value }), typeof(PlaylistSongInfo)); await e.Channel.SendMessage($"🎵 `Saved playlist as {name}-{playlist.Id}`").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "load") .Description($"Loads a playlist under a certain name. | `{Prefix}load classical-1`") .Parameter("name", ParameterType.Unparsed) .Do(async e => { var voiceCh = e.User.VoiceChannel; var textCh = e.Channel; if (voiceCh == null || voiceCh.Server != textCh.Server) { await textCh.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); return; } var name = e.GetArg("name")?.Trim().ToLowerInvariant(); if (string.IsNullOrWhiteSpace(name)) { return; } var parts = name.Split('-'); if (parts.Length != 2) { return; } var playlistName = parts[0]; int playlistNumber; if (!int.TryParse(parts[1], out playlistNumber)) { return; } var playlist = DbHandler.Instance.FindOne <MusicPlaylist>( p => p.Id == playlistNumber); if (playlist == null) { await e.Channel.SendMessage("Can't find playlist under that name.").ConfigureAwait(false); return; } var psis = DbHandler.Instance.FindAll <PlaylistSongInfo>(psi => psi.PlaylistId == playlist.Id); var songInfos = psis.Select(psi => DbHandler.Instance .FindOne <DataModels.SongInfo>(si => si.Id == psi.SongInfoId)); await e.Channel.SendMessage($"`Attempting to load {songInfos.Count()} songs`").ConfigureAwait(false); foreach (var si in songInfos) { try { await QueueSong(e.User, textCh, voiceCh, si.Query, true, (MusicType)si.ProviderType).ConfigureAwait(false); } catch (PlaylistFullException) { break; } catch (Exception ex) { Console.WriteLine($"Failed QueueSong in load playlist. {ex}"); } } }); cgb.CreateCommand(Prefix + "playlists") .Alias(Prefix + "pls") .Description($"Lists all playlists. Paginated. 20 per page. Default page is 0. |`{Prefix}pls 1`") .Parameter("num", ParameterType.Optional) .Do(e => { int num = 0; int.TryParse(e.GetArg("num"), out num); if (num < 0) { return; } var result = DbHandler.Instance.GetPlaylistData(num); if (result.Count == 0) { e.Channel.SendMessage($"`No saved playlists found on page {num}`").ConfigureAwait(false); } else { e.Channel.SendMessage($"```js\n--- List of saved playlists ---\n\n" + string.Join("\n", result.Select(r => $"'{r.Name}-{r.Id}' by {r.Creator} ({r.SongCnt} songs)")) + $"\n\n --- Page {num} ---```").ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "deleteplaylist") .Alias(Prefix + "delpls") .Description($"Deletes a saved playlist. Only if you made it or if you are the bot owner. | `{Prefix}delpls animu-5`") .Parameter("pl", ParameterType.Required) .Do(async e => { var pl = e.GetArg("pl").Trim().Split('-')[1]; if (string.IsNullOrWhiteSpace(pl)) { return; } var plnum = int.Parse(pl); if (MidnightBot.IsOwner(e.User.Id)) { DbHandler.Instance.Delete <MusicPlaylist>(plnum); } else { DbHandler.Instance.DeleteWhere <MusicPlaylist>(mp => mp.Id == plnum && (long)e.User.Id == mp.CreatorId); } await e.Channel.SendMessage("`Ok.` :ok:").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "goto") .Description($"Goes to a specific time in seconds in a song. | `{Prefix}goto 30`") .Parameter("time") .Do(async e => { var skipToStr = e.GetArg("time")?.Trim(); MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (e.User.VoiceChannel != musicPlayer.PlaybackVoiceChannel) { return; } int skipTo; if (!int.TryParse(skipToStr, out skipTo) || skipTo < 0) { return; } var currentSong = musicPlayer.CurrentSong; if (currentSong == null) { return; } //currentSong.PrintStatusMessage = false; var gotoSong = currentSong.Clone(); gotoSong.SkipTo = skipTo; musicPlayer.AddSong(gotoSong, 0); musicPlayer.Next(); var minutes = (skipTo / 60).ToString(); var seconds = (skipTo % 60).ToString(); if (minutes.Length == 1) { minutes = "0" + minutes; } if (seconds.Length == 1) { seconds = "0" + seconds; } await e.Channel.SendMessage($"`Skipped to {minutes}:{seconds}`").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "getlink") .Alias(Prefix + "gl") .Description("Shows a link to the song in the queue by index, or the currently playing song by default.") .Parameter("index", ParameterType.Optional) .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } int index; string arg = e.GetArg("index")?.Trim(); if (!string.IsNullOrEmpty(arg) && int.TryParse(arg, out index)) { var selSong = musicPlayer.Playlist.DefaultIfEmpty(null).ElementAtOrDefault(index - 1); if (selSong == null) { await e.Channel.SendMessage("Could not select song, likely wrong index"); } else { await e.Channel.SendMessage($"🎶`Selected song {selSong.SongInfo.Title}:` <{selSong.SongInfo.Query}>").ConfigureAwait(false); } } else { var curSong = musicPlayer.CurrentSong; if (curSong == null) { return; } await e.Channel.SendMessage($"🎶`Current song:` <{curSong.SongInfo.Query}>").ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "autoplay") .Alias(Prefix + "ap") .Description("Toggles autoplay - When the song is finished, automatically queue a related youtube song. (Works only for youtube songs and when queue is empty)") .Do(async e => { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { return; } if (!musicPlayer.ToggleAutoplay()) { await e.Channel.SendMessage("🎶`Autoplay disabled.`").ConfigureAwait(false); } else { await e.Channel.SendMessage("🎶`Autoplay enabled.`").ConfigureAwait(false); } }); }); }
public bool CanRun(Command command, User user, Channel channel, out string error) { error = String.Empty; if (!MidnightBot.Ready) { return(false); } if (channel.IsPrivate) { return(true); } if (ConfigHandler.IsUserBlacklisted(user.Id) || (!channel.IsPrivate && (ConfigHandler.IsServerBlacklisted(channel.Server.Id) || ConfigHandler.IsChannelBlacklisted(channel.Id)))) { return(false); } if (timeBlackList.Contains(user.Id)) { return(false); } if (!channel.IsPrivate && !channel.Server.CurrentUser.GetPermissions(channel).SendMessages) { return(false); } timeBlackList.Add(user.Id); ServerPermissions perms; PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms); AddUserCooldown(user.Server.Id, user.Id, command.Text.ToLower()); if (!MidnightBot.IsOwner(user.Id) && commandCooldowns.Keys.Contains(user.Server.Id + ":" + command.Text.ToLower())) { if (perms?.Verbose == true) { error = $"{user.Mention} Du hast einen Cooldown auf diesem Befehl."; } return(false); } try { //is it a permission command? // if it is, check if the user has the correct role // if yes return true, if no return false if (command.Category == "Permissions") { Discord.Role role = null; try { role = PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server)); } catch { } if (user.Server.Owner.Id == user.Id || (role != null && user.HasRole(role)) || MidnightBot.IsOwner(user.Id)) { return(true); } throw new Exception($"Du hast nicht die benötigte Rolle (**{(perms?.PermissionsControllerRole ?? "Admin")}**) um die Berechtigungen zu ändern."); } var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel); string msg; if (permissionType == PermissionsHandler.PermissionBanType.ServerBanModule && command.Category.ToLower() == "nsfw") { msg = $"**{command.Category}** Modul wurde gebannt von diesem **server**.\nNSFW Modul ist standardmäßig deaktiviert. Der Server-Owner kann `;sm nsfw enable` eingeben, um es zu aktivieren."; } else { switch (permissionType) { case PermissionsHandler.PermissionBanType.None: return(true); case PermissionsHandler.PermissionBanType.ServerBanCommand: msg = $"Befehl **{command.Text}** wurde gebannt von diesem **Server**."; break; case PermissionsHandler.PermissionBanType.ServerBanModule: msg = $"Modul **{command.Category}** wurde gebannt von diesem **Server**."; break; case PermissionsHandler.PermissionBanType.ChannelBanCommand: msg = $"Befehl **{command.Text}** wurde gebannt von diesem **Channel**."; break; case PermissionsHandler.PermissionBanType.ChannelBanModule: msg = $"Modul **{command.Category}** wurde gebannt von diesem **Channel**."; break; case PermissionsHandler.PermissionBanType.RoleBanCommand: msg = $"Du hast nicht die benötigte **Rolle** welche dich zur Benutzung vom **{command.Text}** Befehl berechtigt."; break; case PermissionsHandler.PermissionBanType.RoleBanModule: msg = $"Du hast keine **Rolle** welche dich zur Benutzung vom **{command.Category}** Modul berechtigt."; break; case PermissionsHandler.PermissionBanType.UserBanCommand: msg = $"{user.Mention}, Du wurdest gebannt von der Benutzung des **{command.Text}** Befehls."; break; case PermissionsHandler.PermissionBanType.UserBanModule: msg = $"{user.Mention}, Du wurdest gebannt von der Benutzung des **{command.Category}** Modules."; break; default: return(true); } } if (PermissionsHandler.PermissionsDict[user.Server.Id].Verbose) //if verbose - print errors { error = msg; } return(false); } catch (Exception ex) { Console.WriteLine($"Exception in canrun: {ex}"); try { if (perms != null && perms.Verbose) { //if verbose - print errors error = ex.Message; } } catch (Exception ex2) { Console.WriteLine($"SERIOUS PERMISSION ERROR {ex2}\n\nUser:{user} Server: {user?.Server?.Name}/{user?.Server?.Id}"); } return(false); } }
public RatelimitCommand(DiscordModule module) : base(module) { MidnightBot.Client.MessageReceived += async(s, e) => { if (e.Channel.IsPrivate || e.User.Id == MidnightBot.Client.CurrentUser.Id || MidnightBot.IsOwner(e.User.Id)) { return; } ConcurrentDictionary <ulong, DateTime> userTimePair; if (!RatelimitingChannels.TryGetValue(e.Channel.Id, out userTimePair)) { return; } DateTime lastMessageTime; if (userTimePair.TryGetValue(e.User.Id, out lastMessageTime)) { if (DateTime.Now - lastMessageTime < ratelimitTime) { try { await e.Message.Delete().ConfigureAwait(false); } catch { } return; } } userTimePair.AddOrUpdate(e.User.Id, id => DateTime.Now, (id, dt) => DateTime.Now); }; }
public override void Install(ModuleManager manager) { var client = manager.Client; var serializer = new ManateeSerializer(); TrelloConfiguration.Serializer = serializer; TrelloConfiguration.Deserializer = serializer; TrelloConfiguration.JsonFactory = new ManateeFactory(); TrelloConfiguration.RestClientProvider = new Manatee.Trello.WebApi.WebApiClientProvider(); TrelloAuthorization.Default.AppKey = MidnightBot.Creds.TrelloAppKey; //TrelloAuthorization.Default.UserToken = "[your user token]"; Discord.Channel bound = null; Board board = null; List <string> last5ActionIDs = null; t.Elapsed += async(s, e) => { try { if (board == null || bound == null) { return; //do nothing if there is no bound board } board.Refresh(); var cur5Actions = board.Actions.Take(board.Actions.Count() < 5 ? board.Actions.Count() : 5); var cur5ActionsArray = cur5Actions as Action[] ?? cur5Actions.ToArray(); if (last5ActionIDs == null) { last5ActionIDs = cur5ActionsArray.Select(a => a.Id).ToList(); return; } foreach (var a in cur5ActionsArray.Where(ca => !last5ActionIDs.Contains(ca.Id))) { await bound.Send("**--TRELLO NOTIFICATION--**\n" + a.ToString()).ConfigureAwait(false); } last5ActionIDs.Clear(); last5ActionIDs.AddRange(cur5ActionsArray.Select(a => a.Id)); } catch (Exception ex) { Console.WriteLine("Timer failed " + ex.ToString()); } }; manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); cgb.CreateCommand(Prefix + "bind") .Description("Bindet einen trello Bot an einen einzigen Server. " + "Du erhälst Benachrichtigungen, wenn etwas entfernt, oder hinzugefügt wird." + $" | `{Prefix}bind [board_id]`") .Parameter("board_id", Discord.Commands.ParameterType.Required) .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id)) { return; } if (bound != null) { return; } try { bound = e.Channel; board = new Board(e.GetArg("board_id").Trim()); board.Refresh(); await e.Channel.SendMessage("Erfolgreich zu diesem Board und Channel gebunden " + board.Name).ConfigureAwait(false); t.Start(); } catch (Exception ex) { Console.WriteLine("Board konnte nicht beigetreten werden. " + ex.ToString()); } }); cgb.CreateCommand(Prefix + "unbind") .Description("Entknüpft einen Bot vom Channel und Board.") .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id)) { return; } if (bound == null || bound != e.Channel) { return; } t.Stop(); bound = null; board = null; await e.Channel.SendMessage("Erfolgreich trello von diesem Channel entknüpft.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "lists") .Alias(Prefix + "list") .Description("Listet alle Listen") .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id)) { return; } if (bound == null || board == null || bound != e.Channel) { return; } await e.Channel.SendMessage("Lists for a board '" + board.Name + "'\n" + string.Join("\n", board.Lists.Select(l => "**• " + l.ToString() + "**"))) .ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cards") .Description($"Lists all cards from the supplied list. You can supply either a name or an index. | `{Prefix}cards index`") .Parameter("list_name", Discord.Commands.ParameterType.Unparsed) .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id)) { return; } if (bound == null || board == null || bound != e.Channel || e.GetArg("list_name") == null) { return; } int num; var success = int.TryParse(e.GetArg("list_name"), out num); List list = null; if (success && num <= board.Lists.Count() && num > 0) { list = board.Lists[num - 1]; } else { list = board.Lists.FirstOrDefault(l => l.Name == e.GetArg("list_name")); } if (list != null) { await e.Channel.SendMessage("There are " + list.Cards.Count() + " cards in a **" + list.Name + "** list\n" + string.Join("\n", list.Cards.Select(c => "**• " + c.ToString() + "**"))) .ConfigureAwait(false); } else { await e.Channel.SendMessage("No such list.").ConfigureAwait(false); } }); }); }
internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel) { var server = user.Server; ServerPermissions serverPerms = PermissionsDict.GetOrAdd(server.Id, id => new ServerPermissions(id, server.Name)); bool val; Permissions perm; //If User is Owner. He can run blocked commands and modules if (MidnightBot.IsOwner(user.Id)) { return(PermissionBanType.None); } //server if (serverPerms.Permissions.Modules.TryGetValue(command.Category, out val) && val == false) { return(PermissionBanType.ServerBanModule); } if (serverPerms.Permissions.Commands.TryGetValue(command.Text, out val) && val == false) { return(PermissionBanType.ServerBanCommand); } //channel if (serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perm) && perm.Modules.TryGetValue(command.Category, out val) && val == false) { return(PermissionBanType.ChannelBanModule); } if (serverPerms.ChannelPermissions.TryGetValue(channel.Id, out perm) && perm.Commands.TryGetValue(command.Text, out val) && val == false) { return(PermissionBanType.ChannelBanCommand); } //ROLE PART - TWO CASES // FIRST CASE: // IF EVERY ROLE USER HAS IS BANNED FROM THE MODULE, // THAT MEANS USER CANNOT RUN THIS COMMAND // IF AT LEAST ONE ROLE EXIST THAT IS NOT BANNED, // USER CAN RUN THE COMMAND var foundNotBannedRole = false; foreach (var role in user.Roles) { //if every role is banned from using the module -> rolebanmodule if (serverPerms.RolePermissions.TryGetValue(role.Id, out perm) && perm.Modules.TryGetValue(command.Category, out val) && val == false) { continue; } foundNotBannedRole = true; break; } if (!foundNotBannedRole) { return(PermissionBanType.RoleBanModule); } // SECOND CASE: // IF EVERY ROLE USER HAS IS BANNED FROM THE COMMAND, // THAT MEANS USER CANNOT RUN THAT COMMAND // IF AT LEAST ONE ROLE EXISTS THAT IS NOT BANNED, // USER CAN RUN THE COMMAND foundNotBannedRole = false; foreach (var role in user.Roles) { //if every role is banned from using the module -> rolebanmodule if (serverPerms.RolePermissions.TryGetValue(role.Id, out perm) && perm.Commands.TryGetValue(command.Text, out val) && val == false) { continue; } else { foundNotBannedRole = true; break; } } if (!foundNotBannedRole) { return(PermissionBanType.RoleBanCommand); } //user if (serverPerms.UserPermissions.TryGetValue(user.Id, out perm) && perm.Modules.TryGetValue(command.Category, out val) && val == false) { return(PermissionBanType.UserBanModule); } if (serverPerms.UserPermissions.TryGetValue(user.Id, out perm) && perm.Commands.TryGetValue(command.Text, out val) && val == false) { return(PermissionBanType.UserBanCommand); } return(PermissionBanType.None); }
public static Func <Command, User, Channel, bool> OwnerOnly() => (com, user, ch) => MidnightBot.IsOwner(user.Id);