Esempio n. 1
0
 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);
     };
 }
Esempio n. 2
0
        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 { }
            };
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
 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 { }
            };
        }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
        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 { }
            };
        }
Esempio n. 8
0
        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;
        }
Esempio n. 9
0
        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 { }
            };
        }
Esempio n. 10
0
        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 { }
            };
        }
Esempio n. 11
0
        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 { }
            };
        }
Esempio n. 12
0
        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 { }
            };
        }
Esempio n. 13
0
        public Remind(DiscordModule module)
            : base(module)
        {
            var remList = DbHandler.Instance.GetAllRows<Reminder>();

            reminders = remList.Select(StartNewReminder).ToList();
        }
Esempio n. 14
0
        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();
        }
Esempio n. 15
0
        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 { }
            };
        }
Esempio n. 16
0
 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 { }
         };
     };
 }
Esempio n. 17
0
        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();
        }
Esempio n. 18
0
        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();
        }
Esempio n. 19
0
        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();
        }
Esempio n. 20
0
 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 { }
     };
 }
Esempio n. 21
0
        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));
        }
Esempio n. 22
0
        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();
        }
Esempio n. 23
0
 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();
     }
 }
Esempio n. 24
0
        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);
                }
            };
        }
Esempio n. 25
0
        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);
            };
        }
Esempio n. 26
0
        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();
            }

        }
Esempio n. 27
0
 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 { }
     };
 }
Esempio n. 28
0
        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 { }
                };
            };
        }
Esempio n. 29
0
        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));
        }
Esempio n. 30
0
 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);
     };
 }
Esempio n. 31
0
        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));
            }
        }
Esempio n. 32
0
        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}");
                }
            };
        }
Esempio n. 33
0
        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));
            }
        }
Esempio n. 34
0
        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}");
                }
            };
        }
Esempio n. 35
0
        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;
        }
Esempio n. 36
0
 public TriviaCommands(DiscordModule module) : base(module)
 {
 }
Esempio n. 37
0
        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)
 {
 }
Esempio n. 39
0
 public RipCommand(DiscordModule module) : base(module)
 {
 }
Esempio n. 40
0
 public OsuCommands(DiscordModule module) : base(module)
 {
 }
Esempio n. 41
0
 public MemegenCommands(DiscordModule module)
     : base(module)
 {
 }
Esempio n. 42
0
 public PlantPick(DiscordModule module) : base(module)
 {
     NadekoBot.Client.MessageReceived += PotentialFlowerGeneration;
     rng = new Random();
 }
Esempio n. 43
0
 public RedditCommand(DiscordModule module) : base(module)
 {
 }
Esempio n. 44
0
 public TriviaCommands(DiscordModule module)
     : base(module)
 {
 }
Esempio n. 45
0
        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));
                    }
                }
            });

            };
        }
Esempio n. 46
0
 public SpeedTyping(DiscordModule module) : base(module)
 {
     RunningContests = new ConcurrentDictionary <ulong, TypingGame>();
 }
Esempio n. 47
0
 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"));
 }
Esempio n. 48
0
 public OsuCommands(DiscordModule module) : base(module)
 {
 }
Esempio n. 49
0
 public DrawCommand(DiscordModule module) : base(module) { }
Esempio n. 50
0
 public IncidentsCommands(DiscordModule module)
     : base(module)
 {
 }
        public CustomReactionsCommands(DiscordModule module) : base(module)
        {

        }
Esempio n. 52
0
 public CustomReactionsCommands(DiscordModule module) : base(module)
 {
 }
Esempio n. 53
0
        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);
                }
            };
        }
Esempio n. 54
0
 public InfoCommands(DiscordModule module)
     : base(module)
 {
 }
Esempio n. 55
0
 public MessageRepeater(DiscordModule module) : base(module)
 {
 }
Esempio n. 56
0
 public DiceRollCommand(DiscordModule module) : base(module)
 {
 }
Esempio n. 57
0
 /// <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;
 }
Esempio n. 58
0
        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();

        }
Esempio n. 59
0
 public PollCommand(DiscordModule module) : base(module) { }
Esempio n. 60
0
 public BetrayGame(DiscordModule module) : base(module) { }