public async Task CreateEntry(ModerationLogEntry logEntry, IMessageChannel replyChannel = null)
        {
            if (replyChannel != null)
            {
                await CreateEmbedResponse(logEntry).SendToChannel(replyChannel);
            }

            await _log.LogMessageAsync(new LogMessage(LogSeverity.Info, "ModLog", $"{logEntry.Moderator} performed {logEntry.ActionType}."));

            await PostToLogChannelAsync(logEntry);
        }
        public async Task StartAsync()
        {
            string discordToken = _data.Configuration.Token;

            if (string.IsNullOrEmpty(discordToken))
            {
                await _log.LogMessageAsync(new LogMessage(LogSeverity.Error, "Startup", "The login token in the config.yaml file was not set."));

                return;
            }

            await _discord.LoginAsync(TokenType.Bot, discordToken);

            await _discord.StartAsync();
        }
Beispiel #3
0
        public async Task <string> PasteMessage(IMessage msg)
        {
            string code = msg.Content;
            string lang = "Autodetect";

            if (HasCodeblockFormat(code))
            {
                code = ExtractCodeblockContent(code, out lang);
            }

            var langRes = await PasteMystLanguage.IdentifyByNameAsync(lang);

            if (langRes == null)
            {
                lang = "Autodetect";
            }

            var paste = new PasteMystPasteForm
            {
                Title          = $"paste by {msg.Author.Username}#{msg.Author.Discriminator} [BrackeysBot]",
                ExpireDuration = PasteMystExpiration.Never,
                Pasties        = new[]
                {
                    new PasteMystPastyForm
                    {
                        Title = "(untitled)",
                        // remove trailing newline
                        Code     = code.TrimEnd(Environment.NewLine.ToCharArray()),
                        Language = lang,
                    },
                },
            };

            try
            {
                var res = await paste.PostPasteAsync();

                return($"https://paste.myst.rs/{res.Id}");
            }
            catch (Exception e)
            {
                await _logger.LogMessageAsync(new LogMessage(LogSeverity.Warning, "Paste", $"failed to paste: {e}"));


                return(null);
            }
        }
Beispiel #4
0
        private async Task UpdateCategoryCount()
        {
            if (ClientUpAndRunning() && CategoryConfigurationAvailable())
            {
                int memberCount               = _discord.GetGuild(_config.GuildID).MemberCount;
                ICategoryChannel channel      = _discord.GetChannel(_config.InfoCategoryId) as ICategoryChannel;
                string           categoryName = _config.InfoCategoryDisplay.Replace("%s%", $"{memberCount}");

                if (CategoryShouldUpdate(channel, categoryName))
                {
                    await channel.ModifyAsync(x => x.Name = categoryName);
                }
            }
            else
            {
                await _loggingService.LogMessageAsync(new LogMessage(LogSeverity.Verbose, "ServerInfoService", $"Discord is {_discord}, Guild is {_discord.GetGuild(_config.GuildID)}, InfoCategory is {_config.InfoCategoryDisplay}, InfoCategoryId is {_config.InfoCategoryId}"));
            }
        }
Beispiel #5
0
        public async void Initialize()
        {
            int essentialCount = 0, otherCount = 0;

            foreach (Type essential in _moduleTypes.Where(t => t.HasAttribute <EssentialModuleAttribute>()))
            {
                await _commands.AddModuleAsync(essential, _services);

                essentialCount++;
            }
            foreach (var config in _data.Configuration.ModuleConfigurations)
            {
                if (config.Value)
                {
                    await _commands.AddModuleAsync(GetModuleTypeByName(config.Key), _services);

                    otherCount++;
                }
            }

            await _log.LogMessageAsync(new LogMessage(LogSeverity.Info, "Modules",
                                                      $"Initialized the module service with {essentialCount} essential module(s) and {otherCount} other module(s)."));
        }
        private void CheckTemporaryInfractions()
        {
            DateTime    now   = DateTime.UtcNow;
            SocketGuild guild = _client.GetGuild(_data.Configuration.GuildID);

            int resolvedCounter = 0;

            foreach (UserData user in _data.UserData.GetUsersWithTemporaryInfractions())
            {
                if (user.HasTemporaryInfraction(TemporaryInfractionType.TempBan))
                {
                    TemporaryInfraction infraction = user.TemporaryInfractions.First(t => t.Type == TemporaryInfractionType.TempBan);
                    if (infraction.Expire <= now)
                    {
                        guild.RemoveBanAsync(user.ID);

                        _ = _modLog.CreateEntry(ModerationLogEntry.New
                                                .WithActionType(ModerationActionType.Unban)
                                                .WithTarget(user.ID)
                                                .WithReason("Temporary ban timed out.")
                                                .WithTime(DateTimeOffset.Now)
                                                .WithModerator(_client.CurrentUser));

                        user.TemporaryInfractions.RemoveAll(i => i.Type == TemporaryInfractionType.TempBan);
                        resolvedCounter++;
                    }
                }
                if (user.HasTemporaryInfraction(TemporaryInfractionType.TempMute))
                {
                    TemporaryInfraction infraction = user.TemporaryInfractions.First(t => t.Type == TemporaryInfractionType.TempMute);
                    if (infraction.Expire <= now)
                    {
                        IRole mutedRole = guild.GetRole(_data.Configuration.MutedRoleID);

                        // If the user is no longer in the server, just remove the entry, but don't attempt to remove his role.
                        IGuildUser guildUser = guild.GetUser(user.ID);
                        guildUser?.RemoveRoleAsync(mutedRole);

                        user.Muted = false;
                        _data.SaveUserData();

                        ModerationLogEntry entry = ModerationLogEntry.New
                                                   .WithActionType(ModerationActionType.Unmute)
                                                   .WithReason("Temporary mute timed out.")
                                                   .WithTime(DateTimeOffset.Now)
                                                   .WithModerator(_client.CurrentUser);

                        if (guildUser != null)
                        {
                            entry = entry.WithTarget(guildUser);
                        }
                        else
                        {
                            entry = entry.WithTarget(user.ID);
                        }

                        _ = _modLog.CreateEntry(entry);

                        user.TemporaryInfractions.RemoveAll(i => i.Type == TemporaryInfractionType.TempMute);
                        resolvedCounter++;
                    }
                }
            }

            if (resolvedCounter > 0)
            {
                _log.LogMessageAsync(new LogMessage(LogSeverity.Info, "TemporaryInfractions", $"Resolved {resolvedCounter} temporary infraction(s)."));
                _data.SaveUserData();
            }
        }