public RatelimitCommand(DiscordModule module) : base(module) { NadekoBot.OnReady += () => NadekoBot.Client.MessageReceived += async (s, e) => { if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.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 FilterWords(DiscordModule module) : base(module) { MidnightBot.Client.MessageReceived += async(sender, args) => { if (args.Channel.IsPrivate || args.User.Id == MidnightBot.Client.CurrentUser.Id) { return; } try { Classes.ServerPermissions serverPerms; if (!IsChannelOrServerFiltering(args.Channel, out serverPerms) || args.User.ServerPermissions.ManageMessages) { return; } var wordsInMessage = args.Message.RawText.ToLowerInvariant().Split(' '); if (serverPerms.Words.Any(w => wordsInMessage.Contains(w))) { await args.Message.Delete().ConfigureAwait(false); IncidentsHandler.Add(args.Server.Id, args.Channel.Id, $"Benutzer [{args.User.Name}/{args.User.Id}] schreib ein " + $"gebanntes Wort im Channel [{args.Channel.Name}/{args.Channel.Id}].\n" + $"`Ganze Nachricht:` {args.Message.Text}"); if (serverPerms.Verbose) { await args.Channel.SendMessage($"{args.User.Mention} Ein, oder mehrere Wörter " + $"in diesem Satz sind hier nicht erlaubt.") .ConfigureAwait(false); } } } catch { } }; }
public PlayingRotate(DiscordModule module) : base(module) { var i = -1; timer.Elapsed += (s, e) => { try { i++; var status = ""; lock (playingPlaceholderLock) { if (PlayingPlaceholders.Count == 0 || WizBot.Config.RotatingStatuses.Count == 0 || i >= PlayingPlaceholders.Count || i >= WizBot.Config.RotatingStatuses.Count) { i = -1; return; } status = WizBot.Config.RotatingStatuses[i]; status = PlayingPlaceholders.Aggregate(status, (current, kvp) => current.Replace(kvp.Key, kvp.Value())); } if (string.IsNullOrWhiteSpace(status)) { return; } Task.Run(() => { WizBot.Client.SetGame(status); }); } catch { } }; timer.Enabled = WizBot.Config.IsRotatingStatus; }
public RatelimitCommand(DiscordModule module) : base(module) { NadekoBot.Client.MessageReceived += async(s, e) => { if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.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 FilterInvitesCommand(DiscordModule module) : base(module) { WizBot.Client.MessageReceived += async(sender, args) => { if (args.Channel.IsPrivate || args.User.Id == WizBot.Client.CurrentUser.Id) { return; } try { Classes.ServerPermissions serverPerms; if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) { return; } if (filterRegex.IsMatch(args.Message.RawText)) { await args.Message.Delete().ConfigureAwait(false); IncidentsHandler.Add(args.Server.Id, $"User [{args.User.Name}/{args.User.Id}] posted " + $"INVITE LINK in [{args.Channel.Name}/{args.Channel.Id}] channel. " + $"Full message: [[{args.Message.Text}]]"); if (serverPerms.Verbose) { await args.Channel.SendMessage($"{args.User.Mention} Invite links are not " + $"allowed on this channel.") .ConfigureAwait(false); } } } catch { } }; }
public PlayingRotate(DiscordModule module) : base(module) { var i = -1; timer.Elapsed += async (s, e) => { try { i++; var status = ""; //wtf am i doing, just use a queue ffs await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); try { if (PlayingPlaceholders.Count == 0 || NadekoBot.Config.RotatingStatuses.Count == 0 || i >= NadekoBot.Config.RotatingStatuses.Count) { i = 0; } status = NadekoBot.Config.RotatingStatuses[i]; status = PlayingPlaceholders.Aggregate(status, (current, kvp) => current.Replace(kvp.Key, kvp.Value())); } finally { playingPlaceholderLock.Release(); } if (string.IsNullOrWhiteSpace(status)) return; await Task.Run(() => { NadekoBot.Client.SetGame(status); }); } catch { } }; NadekoBot.OnReady += () => timer.Enabled = NadekoBot.Config.IsRotatingStatus; }
public FilterInvitesCommand(DiscordModule module) : base(module) { NadekoBot.OnReady += () => NadekoBot.Client.MessageReceived += async (sender, args) => { if (args.Channel.IsPrivate || args.User.Id == NadekoBot.Client.CurrentUser.Id) return; try { Classes.ServerPermissions serverPerms; if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) return; if (filterRegex.IsMatch(args.Message.RawText)) { await args.Message.Delete().ConfigureAwait(false); IncidentsHandler.Add(args.Server.Id, args.Channel.Id, $"User [{args.User.Name}/{args.User.Id}] posted " + $"INVITE LINK in [{args.Channel.Name}/{args.Channel.Id}] channel.\n" + $"`Full message:` {args.Message.Text}"); if (serverPerms.Verbose) await args.Channel.SendMessage($"{args.User.Mention} Invite links are not " + $"allowed on this channel.") .ConfigureAwait(false); } } catch { } }; }
public PlayingRotate(DiscordModule module) : base(module) { var i = -1; timer.Elapsed += (s, e) => { try { i++; var status = ""; lock (playingPlaceholderLock) { if (PlayingPlaceholders.Count == 0) return; if (i >= PlayingPlaceholders.Count) { i = -1; return; } status = NadekoBot.Config.RotatingStatuses[i]; status = PlayingPlaceholders.Aggregate(status, (current, kvp) => current.Replace(kvp.Key, kvp.Value())); } if (string.IsNullOrWhiteSpace(status)) return; Task.Run(() => { NadekoBot.Client.SetGame(status); }); } catch { } }; timer.Enabled = NadekoBot.Config.IsRotatingStatus; }
public LogCommand(DiscordModule module) : base(module) { NadekoBot.Client.MessageReceived += MsgRecivd; NadekoBot.Client.MessageDeleted += MsgDltd; NadekoBot.Client.MessageUpdated += MsgUpdtd; NadekoBot.Client.UserUpdated += UsrUpdtd; NadekoBot.Client.MessageReceived += async(s, e) => { if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) { return; } if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) { return; } try { var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != e.User); if (usr?.Status != UserStatus.Offline) { return; } await e.Channel.SendMessage($"User `{usr.Name}` is offline. PM sent."); await usr.SendMessage( $"User `{e.User.Name}` mentioned you on " + $"`{e.Server.Name}` server while you were offline.\n" + $"`Message:` {e.Message.Text}"); } catch { } }; }
public FilterWords(DiscordModule module) : base(module) { NadekoBot.OnReady += () => NadekoBot.Client.MessageReceived += async(sender, args) => { if (args.Channel.IsPrivate || args.User.Id == NadekoBot.Client.CurrentUser.Id) { return; } try { Classes.ServerPermissions serverPerms; if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) { return; } var wordsInMessage = args.Message.RawText.ToLowerInvariant().Split(' '); if (serverPerms.Words.Any(w => wordsInMessage.Contains(w))) { await args.Message.Delete().ConfigureAwait(false); IncidentsHandler.Add(args.Server.Id, args.Channel.Id, $"User [{args.User.Name}/{args.User.Id}] posted " + $"BANNED WORD in [{args.Channel.Name}/{args.Channel.Id}] channel.\n" + $"`Full message:` {args.Message.Text}"); if (serverPerms.Verbose) { await args.Channel.SendMessage($"{args.User.Mention} One or more of the words you used " + $"in that sentence are not allowed here.") .ConfigureAwait(false); } } } catch { } }; }
public FilterWords(DiscordModule module) : base(module) { NadekoBot.Client.MessageReceived += async (sender, args) => { if (args.Channel.IsPrivate || args.User.Id == NadekoBot.Client.CurrentUser.Id) return; try { Classes.ServerPermissions serverPerms; if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) return; var wordsInMessage = args.Message.RawText.ToLowerInvariant().Split(' '); if (serverPerms.Words.Any(w => wordsInMessage.Contains(w))) { await args.Message.Delete(); IncidentsHandler.Add(args.Server.Id, $"User [{args.User.Name}/{args.User.Id}] posted " + $"BANNED WORD in [{args.Channel.Name}/{args.Channel.Id}] channel. " + $"Full message: [[{args.Message.Text}]]"); if (serverPerms.Verbose) await args.Channel.SendMessage($"{args.User.Mention} One or more of the words you used " + $"in that sentence are not allowed here."); } } catch { } }; }
public LogCommand(DiscordModule module) : base(module) { NadekoBot.Client.MessageReceived += MsgRecivd; NadekoBot.Client.MessageDeleted += MsgDltd; NadekoBot.Client.MessageUpdated += MsgUpdtd; NadekoBot.Client.UserUpdated += UsrUpdtd; NadekoBot.Client.UserBanned += UsrBanned; NadekoBot.Client.MessageReceived += async (s, e) => { if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) return; if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return; try { var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != e.User); if (usr?.Status != UserStatus.Offline) return; await e.Channel.SendMessage($"User `{usr.Name}` is offline. PM sent."); await usr.SendMessage( $"User `{e.User.Name}` mentioned you on " + $"`{e.Server.Name}` server while you were offline.\n" + $"`Message:` {e.Message.Text}"); } catch { } }; }
public Remind(DiscordModule module) : base(module) { var remList = DbHandler.Instance.GetAllRows<Reminder>(); reminders = remList.Select(StartNewReminder).ToList(); }
public Remind(DiscordModule module) : base(module) { var remList = DbHandler.Instance.GetAllRows <Reminder>(); Console.WriteLine(string.Join("\n-", remList.Select(r => r.When.ToString()))); reminders = remList.Select(StartNewReminder).ToList(); }
public FilterInvitesCommand(DiscordModule module) : base(module) { MidnightBot.Client.MessageReceived += async(sender, args) => { if (args.Channel.IsPrivate || args.User.Id == MidnightBot.Client.CurrentUser.Id) { return; } try { Classes.ServerPermissions serverPerms; if (!IsChannelOrServerFiltering(args.Channel, out serverPerms)) { return; } if (filterRegex.IsMatch(args.Message.RawText)) { await args.Message.Delete().ConfigureAwait(false); IncidentsHandler.Add(args.Server.Id, args.Channel.Id, $"Benutzer [{args.User.Name}/{args.User.Id}] hat einen " + $"EINLADUNGS LINK im [{args.Channel.Name}/{args.Channel.Id}] Channel gepostet.\n" + $"`Ganze Nachricht:` {args.Message.Text}"); if (serverPerms.Verbose) { await args.Channel.SendMessage($"{args.User.Mention} Invite Links sind " + $"in diesem Channel nicht erlaubt.") .ConfigureAwait(false); } } } catch { } }; }
public CrossServerTextChannel(DiscordModule module) : base(module) { WizBot.OnReady += () => { WizBot.Client.MessageReceived += async(s, e) => { try { if (e.User.Id == WizBot.Client.CurrentUser.Id) { return; } foreach (var subscriber in Subscribers) { var set = subscriber.Value; if (!set.Contains(e.Channel)) { continue; } foreach (var chan in set.Except(new[] { e.Channel })) { await chan.SendMessage(GetText(e.Server, e.Channel, e.User, e.Message)).ConfigureAwait(false); } } } catch { } }; WizBot.Client.MessageUpdated += async(s, e) => { try { if (e.After?.User?.Id == null || e.After.User.Id == WizBot.Client.CurrentUser.Id) { return; } foreach (var subscriber in Subscribers) { var set = subscriber.Value; if (!set.Contains(e.Channel)) { continue; } foreach (var chan in set.Except(new[] { e.Channel })) { var msg = chan.Messages .FirstOrDefault(m => m.RawText == GetText(e.Server, e.Channel, e.User, e.Before)); if (msg != default(Message)) { await msg.Edit(GetText(e.Server, e.Channel, e.User, e.After)).ConfigureAwait(false); } } } } catch { } }; }; }
public StreamNotifications(DiscordModule module) : base(module) { checkTimer.Elapsed += async(s, e) => { try { var streams = NadekoBot.Config.ObservingStreams; if (streams == null || !streams.Any()) { return; } foreach (var stream in streams) { Tuple <bool, string> data; try { data = await GetStreamStatus(stream); } catch { continue; } if (data.Item1 != stream.LastStatus) { stream.LastStatus = data.Item1; var server = NadekoBot.Client.GetServer(stream.ServerId); var channel = server?.GetChannel(stream.ChannelId); if (channel == null) { continue; } var msg = $"`{stream.Username}`'s stream is now " + $"**{(data.Item1 ? "ONLINE" : "OFFLINE")}** with " + $"**{data.Item2}** viewers."; if (stream.LastStatus) { if (stream.Type == StreamNotificationConfig.StreamType.Hitbox) { msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】"; } else if (stream.Type == StreamNotificationConfig.StreamType.Twitch) { msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】"; } else if (stream.Type == StreamNotificationConfig.StreamType.YoutubeGaming) { msg += $"\n`Here is the Link:`【 not implemented yet - {stream.Username} 】"; } } await channel.SendMessage(msg); } } } catch { } ConfigHandler.SaveConfig(); }; checkTimer.Start(); }
public HaskellRepl(DiscordModule module) : base(module) { //start haskell interpreter haskellThread = new Thread(new ThreadStart(() => { var p = Process.Start(new ProcessStartInfo { FileName = "stack", //shouldn't use repl, but a Language.Haskell.Interpreter somehow Arguments = "repl", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true, }); Task.Run(async () => { while (true) { while (commandQueue.Count == 0) await Task.Delay(100); //read from queue KeyValuePair<string, Channel> com; if (!commandQueue.TryDequeue(out com)) { await Task.Delay(100); continue; } //var bytes = Encoding.ASCII.GetBytes(com.Key); //send the command to the process p.StandardInput.WriteLine(com.Key); //wait 50 ms for execution await Task.Delay(50); //read everything from the output var outBuffer = new byte[1500]; p.StandardOutput.BaseStream.Read(outBuffer, 0, 1500); var outStr = Encoding.ASCII.GetString(outBuffer); //send to channel await com.Value.SendMessage($"```hs\nPrelude> {com.Key}\n" + outStr + "\n```"); } }); })); haskellThread.Start(); }
public HaskellRepl(DiscordModule module) : base(module) { //start haskell interpreter haskellThread = new Thread(new ThreadStart(() => { var p = Process.Start(new ProcessStartInfo { FileName = "stack", //shouldn't use repl, but a Language.Haskell.Interpreter somehow Arguments = "repl", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true, }); Task.Run(async() => { while (true) { while (commandQueue.Count == 0) { await Task.Delay(100); } //read from queue KeyValuePair <string, Channel> com; if (!commandQueue.TryDequeue(out com)) { await Task.Delay(100); continue; } //var bytes = Encoding.ASCII.GetBytes(com.Key); //send the command to the process p.StandardInput.WriteLine(com.Key); //wait 50 ms for execution await Task.Delay(50); //read everything from the output var outBuffer = new byte[1500]; p.StandardOutput.BaseStream.Read(outBuffer, 0, 1500); var outStr = Encoding.ASCII.GetString(outBuffer); //send to channel await com.Value.SendMessage($"```hs\nPrelude> {com.Key}\n" + outStr + "\n```"); } }); })); haskellThread.Start(); }
public LoLCommands(DiscordModule module) : base(module) { clearTimer.Interval = new TimeSpan(0, 10, 0).TotalMilliseconds; clearTimer.Start(); clearTimer.Elapsed += (s, e) => { try { lock (cacheLock) CachedChampionImages = CachedChampionImages .Where(kvp => DateTime.Now - kvp.Value.AddedAt > new TimeSpan(1, 0, 0)) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); } catch { } }; }
public ServerGreetCommand(DiscordModule module) : base(module) { AnnouncementsDictionary = new ConcurrentDictionary<ulong, AnnounceControls>(); NadekoBot.Client.UserJoined += UserJoined; NadekoBot.Client.UserLeft += UserLeft; var data = Classes.DbHandler.Instance.GetAllRows<DataModels.Announcement>(); if (!data.Any()) return; foreach (var obj in data) AnnouncementsDictionary.TryAdd((ulong)obj.ServerId, new AnnounceControls(obj)); }
public StreamNotifications(DiscordModule module) : base(module) { checkTimer.Elapsed += async (s, e) => { cachedStatuses.Clear(); try { var streams = SpecificConfigurations.Default.AllConfigs.SelectMany(c => c.ObservingStreams); if (!streams.Any()) return; foreach (var stream in streams) { Tuple<bool, string> data; try { data = await GetStreamStatus(stream); } catch { continue; } if (data.Item1 != stream.LastStatus) { stream.LastStatus = data.Item1; var server = NadekoBot.Client.GetServer(stream.ServerId); var channel = server?.GetChannel(stream.ChannelId); if (channel == null) continue; var msg = $"`{stream.Username}`'s stream is now " + $"**{(data.Item1 ? "ONLINE" : "OFFLINE")}** with " + $"**{data.Item2}** viewers."; if (stream.LastStatus) if (stream.Type == StreamNotificationConfig.StreamType.Hitbox) msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】"; else if (stream.Type == StreamNotificationConfig.StreamType.Twitch) msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】"; else if (stream.Type == StreamNotificationConfig.StreamType.Beam) msg += $"\n`Here is the Link:`【 http://www.beam.pro/{stream.Username}/ 】"; else if (stream.Type == StreamNotificationConfig.StreamType.YoutubeGaming) msg += $"\n`Here is the Link:`【 not implemented yet - {stream.Username} 】"; await channel.SendMessage(msg); } } } catch { } ConfigHandler.SaveConfig(); }; checkTimer.Start(); }
public ConverterCommand(DiscordModule module) : base(module) { if (unitTables == null) { CultureInfo ci = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = ci; unitTables = new List <UnitTable>(); unitTables.Add(UnitTable.LengthTable); unitTables.Add(UnitTable.TemperatureTable); unitTables.Add(UnitTable.VolumeTable); unitTables.Add(UnitTable.WeightTable); reInitCurrencyConverterTable(); } }
public VoicePlusTextCommand(DiscordModule module) : base(module) { // changing servers may cause bugs NadekoBot.Client.UserUpdated += async(sender, e) => { try { var config = SpecificConfigurations.Default.Of(e.Server.Id); if (e.Before.VoiceChannel == e.After.VoiceChannel) { return; } if (!config.VoicePlusTextEnabled) { return; } var beforeVch = e.Before.VoiceChannel; if (beforeVch != null) { var textChannel = e.Server.FindChannels(GetChannelName(beforeVch.Name), ChannelType.Text).FirstOrDefault(); if (textChannel != null) { await textChannel.AddPermissionsRule(e.Before, new ChPermOverride(readMessages : PermValue.Deny, sendMessages : PermValue.Deny)); } } var afterVch = e.After.VoiceChannel; if (afterVch != null) { var textChannel = e.Server.FindChannels( GetChannelName(afterVch.Name), ChannelType.Text) .FirstOrDefault(); if (textChannel == null) { textChannel = (await e.Server.CreateChannel(GetChannelName(afterVch.Name), ChannelType.Text)); await textChannel.AddPermissionsRule(e.Server.EveryoneRole, new ChPermOverride(readMessages : PermValue.Deny, sendMessages : PermValue.Deny)); } await textChannel.AddPermissionsRule(e.After, new ChPermOverride(readMessages : PermValue.Allow, sendMessages : PermValue.Allow)); } } catch (Exception ex) { Console.WriteLine(ex); } }; }
public Bomberman(DiscordModule module) : base(module) { NadekoBot.Client.MessageReceived += async(s, e) => { if (e.Channel.Id != bombGame.ChannelId) { return; } var text = e.Message.Text; await e.Message.Delete(); HandleBombermanCommand(e.User, text); }; }
public ConverterCommand(DiscordModule module) : base(module) { if (unitTables == null) { CultureInfo ci = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = ci; unitTables = new List<UnitTable>(); unitTables.Add(UnitTable.LengthTable); unitTables.Add(UnitTable.TemperatureTable); unitTables.Add(UnitTable.VolumeTable); unitTables.Add(UnitTable.WeightTable); reInitCurrencyConverterTable(); } }
public CrossServerTextChannel(DiscordModule module) : base(module) { NadekoBot.OnReady += () => { NadekoBot.Client.MessageReceived += async (s, e) => { try { if (e.User.Id == NadekoBot.Client.CurrentUser.Id) return; foreach (var subscriber in Subscribers) { var set = subscriber.Value; if (!set.Contains(e.Channel)) continue; foreach (var chan in set.Except(new[] { e.Channel })) { await chan.SendMessage(GetText(e.Server, e.Channel, e.User, e.Message)).ConfigureAwait(false); } } } catch { } }; NadekoBot.Client.MessageUpdated += async (s, e) => { try { if (e.After?.User?.Id == null || e.After.User.Id == NadekoBot.Client.CurrentUser.Id) return; foreach (var subscriber in Subscribers) { var set = subscriber.Value; if (!set.Contains(e.Channel)) continue; foreach (var chan in set.Except(new[] { e.Channel })) { var msg = chan.Messages .FirstOrDefault(m => m.RawText == GetText(e.Server, e.Channel, e.User, e.Before)); if (msg != default(Message)) await msg.Edit(GetText(e.Server, e.Channel, e.User, e.After)).ConfigureAwait(false); } } } catch { } }; }; }
public ServerGreetCommand(DiscordModule module) : base(module) { AnnouncementsDictionary = new ConcurrentDictionary<ulong, AnnounceControls>(); //gotta subscribe after ready, to prevent trying to send these before all guilds are initialized NadekoBot.OnReady += () => { NadekoBot.Client.UserJoined += UserJoined; NadekoBot.Client.UserLeft += UserLeft; }; var data = Classes.DbHandler.Instance.GetAllRows<DataModels.Announcement>(); if (!data.Any()) return; foreach (var obj in data) AnnouncementsDictionary.TryAdd((ulong)obj.ServerId, new AnnounceControls(obj)); }
public RatelimitCommand(DiscordModule module) : base(module) { NadekoBot.OnReady += () => NadekoBot.Client.MessageReceived += async(s, e) => { if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) { return; } if (NadekoBot.IsOwner(e.User.Id)) { return; } try { var role_devs = e.Server.FindRoles("Developers").FirstOrDefault(); var role_admins = e.Server.FindRoles("Administrators").FirstOrDefault(); var role_mods = e.Server.FindRoles("Moderators").FirstOrDefault(); var role_custom = e.Server.FindRoles("Discord").FirstOrDefault(); if (e.User.HasRole(role_devs) || e.User.HasRole(role_admins) || e.User.HasRole(role_mods) || e.User.HasRole(role_custom)) { return; } } catch { } ConcurrentDictionary <ulong, DateTime> userTimePair; if (!RatelimitingChannels.TryGetValue(e.Channel.Id, out userTimePair)) { return; } DateTime lastMessageTime; if (userTimePair.TryGetValue(e.User.Id, out lastMessageTime)) { TimeSpan ratelimitTime = new TimeSpan(0, 0, 0, slowtime); 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 ServerGreetCommand(DiscordModule module) : base(module) { AnnouncementsDictionary = new ConcurrentDictionary <ulong, AnnounceControls>(); NadekoBot.Client.UserJoined += UserJoined; NadekoBot.Client.UserLeft += UserLeft; var data = Classes.DbHandler.Instance.GetAllRows <Classes._DataModels.Announcement>(); if (!data.Any()) { return; } foreach (var obj in data) { AnnouncementsDictionary.TryAdd((ulong)obj.ServerId, new AnnounceControls(obj)); } }
public AutoAssignRole(DiscordModule module) : base(module) { NadekoBot.Client.UserJoined += (s, e) => { try { var config = SpecificConfigurations.Default.Of(e.Server.Id); var role = e.Server.Roles.Where(r => r.Id == config.AutoAssignedRole).FirstOrDefault(); if (role == null) return; e.User.AddRoles(role); } catch (Exception ex) { Console.WriteLine($"aar exception. {ex}"); } }; }
public ServerGreetCommand(DiscordModule module) : base(module) { AnnouncementsDictionary = new ConcurrentDictionary <ulong, AnnounceControls>(); //gotta subscribe after ready, to prevent trying to send these before all guilds are initialized WizBot.OnReady += () => { WizBot.Client.UserJoined += UserJoined; WizBot.Client.UserLeft += UserLeft; }; var data = Classes.DbHandler.Instance.GetAllRows <DataModels.Announcement>(); if (!data.Any()) { return; } foreach (var obj in data) { AnnouncementsDictionary.TryAdd((ulong)obj.ServerId, new AnnounceControls(obj)); } }
public AutoAssignRole(DiscordModule module) : base(module) { WizBot.OnReady += () => WizBot.Client.UserJoined += (s, e) => { try { var config = SpecificConfigurations.Default.Of(e.Server.Id); var role = e.Server.Roles.Where(r => r.Id == config.AutoAssignedRole).FirstOrDefault(); if (role == null) { return; } e.User.AddRoles(role); } catch (Exception ex) { Console.WriteLine($"aar exception. {ex}"); } }; }
public PlayingRotate(DiscordModule module) : base(module) { var i = -1; timer.Elapsed += async(s, e) => { try { i++; var status = ""; //wtf am i doing, just use a queue ffs await playingPlaceholderLock.WaitAsync().ConfigureAwait(false); try { if (PlayingPlaceholders.Count == 0 || MidnightBot.Config.RotatingStatuses.Count == 0 || i >= MidnightBot.Config.RotatingStatuses.Count) { i = 0; } status = MidnightBot.Config.RotatingStatuses[i]; status = PlayingPlaceholders.Aggregate(status, (current, kvp) => current.Replace(kvp.Key, kvp.Value())); } finally { playingPlaceholderLock.Release(); } if (string.IsNullOrWhiteSpace(status)) { return; } await Task.Run(() => { MidnightBot.Client.SetGame(status); }); } catch { } }; timer.Enabled = MidnightBot.Config.IsRotatingStatus; }
public TriviaCommands(DiscordModule module) : base(module) { }
public VoicePlusTextCommand(DiscordModule module) : base(module) { // changing servers may cause bugs NadekoBot.OnReady += () => NadekoBot.Client.UserUpdated += async (sender, e) => { try { if (e.Server == null) return; var config = SpecificConfigurations.Default.Of(e.Server.Id); if (e.Before.VoiceChannel == e.After.VoiceChannel) return; if (!config.VoicePlusTextEnabled) return; var serverPerms = e.Server.GetUser(NadekoBot.Client.CurrentUser.Id)?.ServerPermissions; if (serverPerms == null) return; if (!serverPerms.Value.ManageChannels || !serverPerms.Value.ManageRoles) { try { await e.Server.Owner.SendMessage( "I don't have manage server and/or Manage Channels permission," + $" so I cannot run voice+text on **{e.Server.Name}** server.").ConfigureAwait(false); } catch { } // meh config.VoicePlusTextEnabled = false; return; } var beforeVch = e.Before.VoiceChannel; if (beforeVch != null) { var textChannel = e.Server.FindChannels(GetChannelName(beforeVch.Name), ChannelType.Text).FirstOrDefault(); if (textChannel != null) await textChannel.AddPermissionsRule(e.Before, new ChPermOverride(readMessages: PermValue.Deny, sendMessages: PermValue.Deny)).ConfigureAwait(false); } var afterVch = e.After.VoiceChannel; if (afterVch != null && e.Server.AFKChannel != afterVch) { var textChannel = e.Server.FindChannels( GetChannelName(afterVch.Name), ChannelType.Text) .FirstOrDefault(); if (textChannel == null) { textChannel = (await e.Server.CreateChannel(GetChannelName(afterVch.Name), ChannelType.Text).ConfigureAwait(false)); await textChannel.AddPermissionsRule(e.Server.EveryoneRole, new ChPermOverride(readMessages: PermValue.Deny, sendMessages: PermValue.Deny)).ConfigureAwait(false); } await textChannel.AddPermissionsRule(e.After, new ChPermOverride(readMessages: PermValue.Allow, sendMessages: PermValue.Allow)).ConfigureAwait(false); } } catch (Exception ex) { Console.WriteLine(ex); } }; }
public ValidLanguagesCommand(DiscordModule module) : base(module) { }
public RipCommand(DiscordModule module) : base(module) { }
public OsuCommands(DiscordModule module) : base(module) { }
public MemegenCommands(DiscordModule module) : base(module) { }
public PlantPick(DiscordModule module) : base(module) { NadekoBot.Client.MessageReceived += PotentialFlowerGeneration; rng = new Random(); }
public RedditCommand(DiscordModule module) : base(module) { }
public StreamNotifications(DiscordModule module) : base(module) { //start checking only after ready, because we need all servers to be initialized NadekoBot.OnReady += () => { Task.Run(async () => { await Task.Delay(60000); while (true) { cachedStatuses.Clear(); try { var streams = SpecificConfigurations.Default.AllConfigs.SelectMany(c => c.ObservingStreams); if (!streams.Any()) return; #if NADEKO_RELEASE var clr = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine($"Getting {streams.Count()} streams."); Console.ForegroundColor = clr; #endif foreach (var stream in streams) { Tuple<bool, string> data; try { data = await GetStreamStatus(stream).ConfigureAwait(false); } catch { continue; } if (data.Item1 != stream.LastStatus) { stream.LastStatus = data.Item1; if (FirstPass) continue; var server = NadekoBot.Client.GetServer(stream.ServerId); var channel = server?.GetChannel(stream.ChannelId); if (channel == null) continue; var msg = $"`{stream.Username}`'s stream is now " + $"**{(data.Item1 ? "ONLINE" : "OFFLINE")}** with " + $"**{data.Item2}** viewers."; if (stream.LastStatus) if (stream.Type == StreamNotificationConfig.StreamType.Hitbox) msg += $"\n`Here is the Link:`【 http://www.hitbox.tv/{stream.Username}/ 】"; else if (stream.Type == StreamNotificationConfig.StreamType.Twitch) msg += $"\n`Here is the Link:`【 http://www.twitch.tv/{stream.Username}/ 】"; else if (stream.Type == StreamNotificationConfig.StreamType.Beam) msg += $"\n`Here is the Link:`【 http://www.beam.pro/{stream.Username}/ 】"; else if (stream.Type == StreamNotificationConfig.StreamType.YoutubeGaming) msg += $"\n`Here is the Link:`【 not implemented yet - {stream.Username} 】"; await channel.SendMessage(msg).ConfigureAwait(false); } } FirstPass = false; #if NADEKO_RELEASE clr = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine($"Done getting streams."); Console.ForegroundColor = clr; #endif } catch { } finally { await Task.Delay(TimeSpan.FromSeconds(60)); } } }); }; }
public SpeedTyping(DiscordModule module) : base(module) { RunningContests = new ConcurrentDictionary <ulong, TypingGame>(); }
public PokemonSearchCommands(DiscordModule module) : base(module) { pokemons = JsonConvert.DeserializeObject <Dictionary <string, SearchPokemon> > (File.ReadAllText("data/pokemon/pokemon_list.json")); pokemonAbilities = JsonConvert.DeserializeObject <Dictionary <string, SearchPokemonAbility> > (File.ReadAllText("data/pokemon/pokemon_abilities.json")); }
public DrawCommand(DiscordModule module) : base(module) { }
public IncidentsCommands(DiscordModule module) : base(module) { }
public CustomReactionsCommands(DiscordModule module) : base(module) { }
public VoicePlusTextCommand(DiscordModule module) : base(module) { // changing servers may cause bugs NadekoBot.Client.UserUpdated += async(sender, e) => { try { if (e.Server == null) { return; } var config = SpecificConfigurations.Default.Of(e.Server.Id); if (e.Before.VoiceChannel == e.After.VoiceChannel) { return; } if (!config.VoicePlusTextEnabled) { return; } var serverPerms = e.Server.GetUser(NadekoBot.Client.CurrentUser.Id)?.ServerPermissions; if (serverPerms == null) { return; } if (!serverPerms.Value.ManageChannels || !serverPerms.Value.ManageRoles) { try { await e.Server.Owner.SendMessage( "I don't have manage server and/or Manage Channels permission," + $" so I cannot run voice+text on **{e.Server.Name}** server.").ConfigureAwait(false); } catch { } // meh config.VoicePlusTextEnabled = false; return; } var beforeVch = e.Before.VoiceChannel; if (beforeVch != null) { var textChannel = e.Server.FindChannels(GetChannelName(beforeVch.Name), ChannelType.Text).FirstOrDefault(); if (textChannel != null) { await textChannel.AddPermissionsRule(e.Before, new ChPermOverride(readMessages : PermValue.Deny, sendMessages : PermValue.Deny)).ConfigureAwait(false); } } var afterVch = e.After.VoiceChannel; if (afterVch != null) { var textChannel = e.Server.FindChannels( GetChannelName(afterVch.Name), ChannelType.Text) .FirstOrDefault(); if (textChannel == null) { textChannel = (await e.Server.CreateChannel(GetChannelName(afterVch.Name), ChannelType.Text).ConfigureAwait(false)); await textChannel.AddPermissionsRule(e.Server.EveryoneRole, new ChPermOverride(readMessages : PermValue.Deny, sendMessages : PermValue.Deny)).ConfigureAwait(false); } await textChannel.AddPermissionsRule(e.After, new ChPermOverride(readMessages : PermValue.Allow, sendMessages : PermValue.Allow)).ConfigureAwait(false); } } catch (Exception ex) { Console.WriteLine(ex); } }; }
public InfoCommands(DiscordModule module) : base(module) { }
public MessageRepeater(DiscordModule module) : base(module) { }
public DiceRollCommand(DiscordModule module) : base(module) { }
/// <summary> /// Creates a new instance of discord command, /// use ": base(module)" in the derived class' /// constructor to make sure module is assigned /// </summary> /// <param name="module">Module this command resides in</param> protected DiscordCommand(DiscordModule module) { this.Module = module; }
public Bomberman(DiscordModule module) : base(module) { for (int i = 0; i < 15; i++) { for (int j = 0; j < 15; j++) { board[i, j] = new Field(); } } NadekoBot.Client.MessageReceived += (s, e) => { if (e.Channel != gameChannel || e.User.Id == NadekoBot.Client.CurrentUser.Id) return; if (e.Message.Text == "w") { board[curI - 1, curJ] = board[curI--, curJ]; board[curI + 1, curJ].player = null; } else if (e.Message.Text == "s") { board[curI + 1, curJ] = board[curI++, curJ]; board[curI - 1, curJ].player = null; } else if (e.Message.Text == "a") { board[curI, curJ - 1] = board[curI, curJ--]; board[curI, curJ + 1].player = null; } else if (e.Message.Text == "d") { board[curI, curJ + 1] = board[curI, curJ++]; board[curI, curJ - 1].player = null; } e.Message.Delete(); }; var t = new Timer(); t.Elapsed += async (s, e) => { if (gameChannel == null) return; var boardStr = new StringBuilder(); for (int i = 0; i < 15; i++) { for (int j = 0; j < 15; j++) { boardStr.Append(board[i, j].ToString()); } boardStr.AppendLine(); } if (godMsg.Id != 0) await godMsg.Edit(boardStr.ToString()); }; t.Interval = 1000; t.Start(); }
public PollCommand(DiscordModule module) : base(module) { }
public BetrayGame(DiscordModule module) : base(module) { }