示例#1
0
        public static async Task Init()
        {
            Config = BotConfigService.GetConfig();

            LogService.Initialize();

            client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel            = LogSeverity.Info,
                MessageCacheSize    = 10000,
                AlwaysDownloadUsers = true,
                DefaultRetryMode    = RetryMode.AlwaysRetry
            });

            SetupEvents();

            // Begin invoke of database mute timers
            Observable
            .Interval(TimeSpan.FromSeconds(1))
                    #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            .Subscribe(x => MuteService.UpdateDatabaseTimers());
                    #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            await client.LoginAsync(TokenType.Bot, Config.Token);

            await client.StartAsync();

            await SetBotStatuses().ConfigureAwait(false);

            await Task.Delay(-1);
        }
示例#2
0
        public static async Task GuildMemberUpdated(SocketGuildUser before, SocketGuildUser after)
        {
            if (!(before is IGuildUser _before) || !(after is IGuildUser _after))
            {
                return;
            }

            if (_before.RoleIds != _after.RoleIds) // Role removed or added
            {
                // Check if muted role was removed or added
                var _mutedRole = await MuteService.GetOrCreateMutedRoleAsync(_before.Guild);

                if (_before.RoleIds.Contains(_mutedRole.Id) && !_after.RoleIds.Contains(_mutedRole.Id))
                {
                    MuteService.RemoveMute(_after);
                }
                else if (!_before.RoleIds.Contains(_mutedRole.Id) && _after.RoleIds.Contains(_mutedRole.Id))
                {
                    MuteService.AddMute(_after);
                }
            }
        }
示例#3
0
        public static async Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState before, SocketVoiceState after)
        {
            // Get guild ID
            if (!(user is IGuildUser _guildUser))
            {
                return;
            }

            if (before.VoiceChannel == null && after.VoiceChannel != null) // If joins channel
            {
                await MuteService.CheckNewUserForVoiceMute(user as IGuildUser);
            }

            if (!before.IsMuted && after.IsMuted) // If server muted
            {
                MuteService.AddVoiceMute(_guildUser.Id, _guildUser.GuildId);
            }
            else if (before.IsMuted && !after.IsMuted) // If un-server muted
            {
                MuteService.RemoveVoiceMute(_guildUser.Id, _guildUser.GuildId);
            }
        }
示例#4
0
        public static async Task UserJoined(SocketGuildUser user)
        {
            await MuteService.CheckNewUserForMute(user);

            await BanService.CheckNewUserForBan(user);

            var _logChannel = LogService.GetLogChannel(user.Guild.Id);

            if (_logChannel == null)
            {
                return;
            }

            var _embed = new EmbedBuilder()
                         .WithTitle($"User joined: {user.Username}#{user.Discriminator}")
                         .WithThumbnailUrl(user.GetAvatarUrl())
                         .WithColor(Color.Blue)
                         .WithDescription($"\nCreated: {user.CreatedAt}" +
                                          $"\nIsBot: {user.IsBot}" +
                                          $"\nID: {user.Id}");

            await _logChannel.SendMessageAsync("", false, _embed.Build());
        }