示例#1
0
        public StatsService(ShardedDiscordClient  client, CommandHandler cmdHandler)
        {

            this.client = client;

            Reset();
            this.client.MessageReceived += _ => Task.FromResult(MessageCounter++);
            cmdHandler.CommandExecuted += (_, e) => CommandsRan++;

            this.client.Disconnected += _ => Reset();

            this.carbonitexTimer = new Timer(async (state) =>
            {
            if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.CarbonKey))
                return;
                try
                {
                    using (var http = new HttpClient())
                    {
                        using (var content = new FormUrlEncodedContent(
                            new Dictionary<string, string> {
                                { "servercount", this.client.GetGuilds().Count.ToString() },
                                { "key", NadekoBot.Credentials.CarbonKey }}))
                        {
                            content.Headers.Clear();
                            content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

                            var res = await http.PostAsync("https://www.carbonitex.net/discord/data/botdata.php", content).ConfigureAwait(false);
                        }
                    };
                }
                catch { }
            }, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
        }
示例#2
0
            public RatelimitCommand()
            {
                this._client = FaultyBot.Client;
                this._log    = LogManager.GetCurrentClassLogger();

                _client.MessageReceived += (umsg) =>
                {
                    var t = Task.Run(async() =>
                    {
                        var usrMsg  = umsg as IUserMessage;
                        var channel = usrMsg.Channel as ITextChannel;

                        if (channel == null || usrMsg.IsAuthor())
                        {
                            return;
                        }
                        Ratelimiter limiter;
                        if (!RatelimitingChannels.TryGetValue(channel.Id, out limiter))
                        {
                            return;
                        }

                        if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
                        {
                            try { await usrMsg.DeleteAsync(); } catch (Exception ex) { _log.Warn(ex); }
                        }
                    });
                    return(Task.CompletedTask);
                };
            }
示例#3
0
        public Music(ILocalization loc, CommandService cmds, ShardedDiscordClient client, IGoogleApiService google) : base(loc, cmds, client)
        {
            //it can fail if its currenctly opened or doesn't exist. Either way i don't care
            try { Directory.Delete(MusicDataPath, true); } catch { }

            Directory.CreateDirectory(MusicDataPath);

            _google = google;
        }
示例#4
0
        public Music(ILocalization loc, CommandService cmds, ShardedDiscordClient client, IGoogleApiService google) : base(loc, cmds, client)
        {
            //it can fail if its currenctly opened or doesn't exist. Either way i don't care
            try { Directory.Delete(MusicDataPath, true); } catch { }

            Directory.CreateDirectory(MusicDataPath);

            _google = google;
        }
示例#5
0
        public StatsService(ShardedDiscordClient client, CommandHandler cmdHandler)
        {
            this.client = client;

            Reset();
            this.client.MessageReceived += _ => Task.FromResult(messageCounter++);
            cmdHandler.CommandExecuted  += (_, e) => commandsRan++;

            this.client.Disconnected += _ => Reset();
        }
示例#6
0
        public Gambling(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
        {
            using (var uow = DbHandler.UnitOfWork())
            {
                var conf = uow.BotConfig.GetOrCreate();

                CurrencyName = conf.CurrencyName;
                CurrencySign = conf.CurrencySign;
                CurrencyPluralName = conf.CurrencyPluralName;
            }
        }
示例#7
0
        public Gambling(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
        {
            using (var uow = DbHandler.UnitOfWork())
            {
                var conf = uow.BotConfig.GetOrCreate();

                CurrencyName       = conf.CurrencyName;
                CurrencySign       = conf.CurrencySign;
                CurrencyPluralName = conf.CurrencyPluralName;
            }
        }
示例#8
0
            public RatelimitCommand()
            {
                this._client = NadekoBot.Client;
                this._log    = LogManager.GetCurrentClassLogger();

                _client.MessageReceived += (umsg) =>
                {
                    var t = Task.Run(async() =>
                    {
                        var usrMsg    = umsg as IUserMessage;
                        var usrGuild  = umsg as IGuildUser;
                        var channel   = usrMsg.Channel as ITextChannel;
                        var usr       = channel.GetUser(umsg.Author.Id) as IUser;
                        ulong[] white = new ulong[] {
                            208441726464032769, // administrators
                            240045137810554880, // moderators
                            240049119035523073, // devs
                            240049515770413057, // moderators I18n
                            240049523370622976  // helpers
                        };
                        var roles = usrGuild.Roles;
                        if (channel == null || usrMsg.IsAuthor() || usrMsg.Author.Id == channel.Guild.OwnerId)
                        {
                            return;
                        }
                        for (int i = 0; i <= roles.Count; i++)
                        {
                            for (int x = 0; x <= white.Length; x++)
                            {
                                var usrGuild_Roles         = channel.Guild.GetRole(white[x]);
                                var usrGuild_Roles_Members = usrGuild_Roles.Members();
                                foreach (IUser user_roles in usrGuild_Roles_Members)
                                {
                                    if (usr == user_roles)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        Ratelimiter limiter;
                        if (!RatelimitingChannels.TryGetValue(channel.Id, out limiter))
                        {
                            return;
                        }

                        if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
                        {
                            try { await usrMsg.DeleteAsync(); } catch (Exception ex) { _log.Warn(ex); }
                        }
                    });
                    return(Task.CompletedTask);
                };
            }
示例#9
0
        public DiscordModule(ILocalization loc, CommandService cmds, ShardedDiscordClient client)
        {
            string prefix;
            if (NadekoBot.ModulePrefixes.TryGetValue(this.GetType().Name, out prefix))
                _prefix = prefix;
            else
                _prefix = "?missing_prefix?";

            _l = loc;
            _commands = cmds;
            _client = client;
            _log = LogManager.GetCurrentClassLogger();
        }
示例#10
0
            public LogCommands(ShardedDiscordClient client)
            {
                //_client.MessageReceived += _client_MessageReceived;
                _client.MessageUpdated        += _client_MessageUpdated;
                _client.MessageDeleted        += _client_MessageDeleted;
                _client.UserBanned            += _client_UserBanned;
                _client.UserUnbanned          += _client_UserUnbanned;
                _client.UserJoined            += _client_UserJoined;
                _client.UserLeft              += _client_UserLeft;
                _client.UserPresenceUpdated   += _client_UserPresenceUpdated;
                _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
                _client.UserUpdated           += _client_UserUpdated;

                _client.ChannelCreated   += _client_ChannelCreated;
                _client.ChannelDestroyed += _client_ChannelDestroyed;
                _client.ChannelUpdated   += _client_ChannelUpdated;
            }
示例#11
0
            public LogCommands(ShardedDiscordClient client)
            {
                //_client.MessageReceived += _client_MessageReceived;
                _client.MessageUpdated += _client_MessageUpdated;
                _client.MessageDeleted += _client_MessageDeleted;
                _client.UserBanned += _client_UserBanned;
                _client.UserUnbanned += _client_UserUnbanned;
                _client.UserJoined += _client_UserJoined;
                _client.UserLeft += _client_UserLeft;
                _client.UserPresenceUpdated += _client_UserPresenceUpdated;
                _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
                _client.UserUpdated += _client_UserUpdated;

                _client.ChannelCreated += _client_ChannelCreated;
                _client.ChannelDestroyed += _client_ChannelDestroyed;
                _client.ChannelUpdated += _client_ChannelUpdated;
            }
示例#12
0
        public DiscordModule(ILocalization loc, CommandService cmds, ShardedDiscordClient client)
        {
            string prefix;

            if (FaultyBot.ModulePrefixes.TryGetValue(this.GetType().Name, out prefix))
            {
                _prefix = prefix;
            }
            else
            {
                _prefix = "?missing_prefix?";
            }

            _l        = loc;
            _commands = cmds;
            _client   = client;
            _log      = LogManager.GetCurrentClassLogger();
        }
示例#13
0
        public StatsService(ShardedDiscordClient client, CommandHandler cmdHandler)
        {
            this.client = client;

            Reset();
            this.client.MessageReceived += _ => Task.FromResult(MessageCounter++);
            cmdHandler.CommandExecuted  += (_, e) => CommandsRan++;

            this.client.Disconnected += _ => Reset();

            this.carbonitexTimer = new Timer(async(state) =>
            {
                if (string.IsNullOrWhiteSpace(FaultyBot.Credentials.CarbonKey))
                {
                    return;
                }
                try
                {
                    using (var http = new HttpClient())
                    {
                        using (var content = new FormUrlEncodedContent(
                                   new Dictionary <string, string> {
                            { "servercount", this.client.GetGuilds().Count.ToString() },
                            { "key", FaultyBot.Credentials.CarbonKey }
                        }))
                        {
                            content.Headers.Clear();
                            content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

                            var res = await http.PostAsync("https://www.carbonitex.net/discord/data/botdata.php", content).ConfigureAwait(false);
                        }
                    };
                }
                catch { }
            }, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
        }
示例#14
0
            public RatelimitCommand()
            {
                this._client = NadekoBot.Client;
                this._log = LogManager.GetCurrentClassLogger();

               _client.MessageReceived += (umsg) =>
                {
                    var t = Task.Run(async () =>
                    {
                        var usrMsg = umsg as IUserMessage;
                        var channel = usrMsg.Channel as ITextChannel;

                        if (channel == null || usrMsg.IsAuthor())
                            return;
                        Ratelimiter limiter;
                        if (!RatelimitingChannels.TryGetValue(channel.Id, out limiter))
                            return;

                        if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
                            try { await usrMsg.DeleteAsync(); } catch (Exception ex) { _log.Warn(ex); }
                    });
                    return Task.CompletedTask;
                };
            }
示例#15
0
            public AntiRaidCommands(ShardedDiscordClient client)
            {
                _log = LogManager.GetCurrentClassLogger();

                client.MessageReceived += (imsg) =>
                {
                    var msg = imsg as IUserMessage;
                    if (msg == null || msg.Author.IsBot)
                        return Task.CompletedTask;

                    var channel = msg.Channel as ITextChannel;
                    if (channel == null)
                        return Task.CompletedTask;

                    var t = Task.Run(async () =>
                    {
                        try
                        {
                            AntiSpamSetting spamSettings;
                            if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings))
                                return;

                            var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, new UserSpamStats(msg.Content),
                                (id, old) => { old.ApplyNextMessage(msg.Content); return old; });

                            if (stats.Count >= spamSettings.MessageThreshold)
                            {
                                if (spamSettings.UserStats.TryRemove(msg.Author.Id, out stats))
                                {
                                    await PunishUsers(spamSettings.Action, await GetMuteRole(channel.Guild), ProtectionType.Spamming, (IGuildUser)msg.Author)
                                        .ConfigureAwait(false);
                                }
                            }
                        }
                        catch { }
                    });
                    return Task.CompletedTask;
                };

                client.UserJoined += (usr) =>
                {
                    if (usr.IsBot)
                        return Task.CompletedTask;

                    AntiRaidSetting settings;
                    if (!antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings))
                        return Task.CompletedTask;

                    var t = Task.Run(async () =>
                    {
                        if (!settings.RaidUsers.Add(usr))
                            return;

                        ++settings.UsersCount;

                        if (settings.UsersCount >= settings.UserThreshold)
                        {
                            var users = settings.RaidUsers.ToArray();
                            settings.RaidUsers.Clear();

                            await PunishUsers(settings.Action, await GetMuteRole(usr.Guild), ProtectionType.Raiding, users).ConfigureAwait(false);
                        }
                        await Task.Delay(1000 * settings.Seconds).ConfigureAwait(false);

                        settings.RaidUsers.TryRemove(usr);
                        --settings.UsersCount;
                    });

                    return Task.CompletedTask;
                };
            }
示例#16
0
 public SelfCommands(ShardedDiscordClient client)
 {
     this._client = client;
 }
示例#17
0
 public Searches(ILocalization loc, CommandService cmds, ShardedDiscordClient client, IGoogleApiService youtube) : base(loc, cmds, client)
 {
     _google = youtube;
 }
示例#18
0
 public CustomReactions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
 {
 }
示例#19
0
 public CustomReactions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
 {
 }
示例#20
0
 public Administration(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
 {
     NadekoBot.CommandHandler.CommandExecuted += DelMsgOnCmd_Handler;
 }
示例#21
0
 public Searches(ILocalization loc, CommandService cmds, ShardedDiscordClient client, IGoogleApiService youtube) : base(loc, cmds, client)
 {
     _google = youtube;
 }
示例#22
0
 public Administration(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
 {
     NadekoBot.CommandHandler.CommandExecuted += DelMsgOnCmd_Handler;
 }
示例#23
0
            public AntiRaidCommands(ShardedDiscordClient client)
            {
                _log = LogManager.GetCurrentClassLogger();

                client.MessageReceived += (imsg) =>
                {
                    var msg = imsg as IUserMessage;
                    if (msg == null || msg.Author.IsBot)
                        return Task.CompletedTask;

                    var channel = msg.Channel as ITextChannel;
                    if (channel == null)
                        return Task.CompletedTask;

                    var t = Task.Run(async () =>
                    {
                        try
                        {
                            AntiSpamSetting spamSettings;
                            if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings))
                                return;

                            var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, new UserSpamStats(msg.Content),
                                (id, old) => { old.ApplyNextMessage(msg.Content); return old; });

                            if (stats.Count >= spamSettings.MessageThreshold)
                            {
                                if (spamSettings.UserStats.TryRemove(msg.Author.Id, out stats))
                                {
                                    await PunishUsers(spamSettings.Action, await GetMuteRole(channel.Guild), ProtectionType.Spamming, (IGuildUser)msg.Author)
                                        .ConfigureAwait(false);
                                }
                            }
                        }
                        catch { }
                    });
                    return Task.CompletedTask;
                };

                client.UserJoined += (usr) =>
                {
                    if (usr.IsBot)
                        return Task.CompletedTask;

                    AntiRaidSetting settings;
                    if (!antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings))
                        return Task.CompletedTask;

                    var t = Task.Run(async () =>
                    {
                        if (!settings.RaidUsers.Add(usr))
                            return;

                        ++settings.UsersCount;

                        if (settings.UsersCount >= settings.UserThreshold)
                        {
                            var users = settings.RaidUsers.ToArray();
                            settings.RaidUsers.Clear();

                            await PunishUsers(settings.Action, await GetMuteRole(usr.Guild), ProtectionType.Raiding, users).ConfigureAwait(false);
                        }
                        await Task.Delay(1000 * settings.Seconds).ConfigureAwait(false);

                        settings.RaidUsers.TryRemove(usr);
                        --settings.UsersCount;
                    });

                    return Task.CompletedTask;
                };
            }
示例#24
0
 public SelfCommands()
 {
     this._client = NadekoBot.Client;
 }
示例#25
0
 public CommandHandler(ShardedDiscordClient client, CommandService commandService)
 {
     _client         = client;
     _commandService = commandService;
     _log            = LogManager.GetCurrentClassLogger();
 }
示例#26
0
 public NSFW(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
 {
 }
示例#27
0
 public NSFW(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
 {
 }
示例#28
0
 public SelfCommands(ShardedDiscordClient client)
 {
     this._client = client;
 }