コード例 #1
0
ファイル: TempMuteCommand.cs プロジェクト: mwerschy/Silk
        public async Task TempMute(CommandContext ctx, DiscordMember user, TimeSpan duration, [RemainingText] string reason = "Not Given.")
        {
            DiscordMember bot = ctx.Guild.CurrentMember;

            if (user.IsAbove(bot))
            {
                await ctx.RespondAsync($"{user.Username} is {user.Roles.Last().Position - bot.Roles.Last().Position} roles above me!")
                .ConfigureAwait(false);

                return;
            }

            GuildConfigModel config = (await _dbService.GetConfigAsync(ctx.Guild.Id)) !;

            if (config.MuteRoleId is 0)
            {
                await ThrowHelper.MuteRoleNotFoundInDatabase(ctx.Channel);

                return;
            }

            UserInfractionModel infraction = await _infractionService.CreateTemporaryInfractionAsync(user, ctx.Member,
                                                                                                     InfractionType.Mute, reason, DateTime.Now.Add(duration));

            await _infractionService.MuteAsync(user, ctx.Channel, infraction);
        }
コード例 #2
0
 public static Embed CreateConfigInfoEmbedLog(GuildConfigModel config)
 {
     return(new EmbedBuilder()
            .WithTitle($"Configuration Info")
            .AddField("Logging Channel", config.LogChannel == 0?"-":MentionUtils.MentionChannel(config.LogChannel))
            .AddField("Staff Roles", config.StaffRoles.GetRoleMentions())
            .WithCurrentTimestamp()
            .WithColor(116, 223, 207)
            .Build());
 }
コード例 #3
0
        public async Task <Result <ulong> > StoreGuildConfig(GuildConfigModel conf)
        {
            var storage = conf.ToStorage();
            var entity  =
                await(_context.GuildConfigModels as IQueryable <GuildConfigStorageModel>)
                .FirstOrDefaultAsync(x =>
                                     x.GuildId == storage.GuildId);

            if (entity is null)
            {
                _context.GuildConfigModels.Add(storage);
            }
            else
            {
                _context.Entry(entity).CurrentValues.SetValues(storage);
            }

            await _context.SaveChangesAsync();

            return(conf.GuildId);
        }
コード例 #4
0
        public async Task SetupGuildConfig()
        {
            var modelResult = await CheckStaffAndRetrieveModel();

            if (modelResult.IsFailure())
            {
                return;
            }
            var model = modelResult.Get();

            _logging.Info($"{Context.User.Username}#{Context.User.Discriminator} in Guild {Context.Guild.Name}({Context.Guild.Id}) calling Setup...");
            await SendChannelMessage(
                $"**Setting up bot...** (Called by {MentionUtils.MentionUser(Context.User.Id)})");
            await SendChannelMessage(
                "**What is the logging channel?**");

            ulong channel = 0;
            var   result  = await _interactivity.NextMessageAsync(CheckUserAndChannelForMessage(message =>
                                                                                                MentionUtils.TryParseChannel(message.Content, out channel)));

            if (!result.IsSuccess)
            {
                _logging.Error("Setup command timed out...");
                return;
            }

            await SendChannelMessage(
                $"**Set logging channel as {MentionUtils.MentionChannel(channel)}...**");
            await SendChannelMessage(
                $"**What are the staff roles? (Type `skip` to skip)**");

            IEnumerable <ulong> roles = new List <ulong>();

            result = await _interactivity.NextMessageAsync(CheckUserAndChannelForMessage(message =>
            {
                try
                {
                    if (message.Content == "skip")
                    {
                        return(true);
                    }

                    _logging.Verbose($"Roles: {message.Content}");
                    roles = message.MentionedRoles.Select(x => x.Id);
                }
                catch (Exception)
                {
                    _logging.Verbose("Role parsing error!");
                    return(false);
                }

                return(true);
            }));

            if (!result.IsSuccess)
            {
                _logging.Error("Setup command timed out...");
                return;
            }

            var guildConfig = new GuildConfigModel(Context.Guild.Id, channel, roles.ToImmutableHashSet());
            await _repo.StoreGuildConfig(guildConfig);

            _logging.Info("Successfully completed setup!");
            await SendChannelMessage(
                $"**Sucessfully completed setup!**");
            await SendChannelMessage(embed : CreateConfigInfoEmbedLog(guildConfig));
        }