コード例 #1
0
        public async Task Jail(string target)
        {
            _logging.Verbose("Jail function called");
            var modelResult = await CheckStaffAndRetrieveModel();

            if (modelResult.IsFailure())
            {
                return;
            }
            _logging.Info($"{Context.User.Username}#{Context.User.Discriminator} in Guild {Context.Guild.Name}({Context.Guild.Id}) calling Jail...");

            var configRes = await _jailSettings.GetJailConfig(Context.Guild.Id);

            if (configRes.IsFailure())
            {
                return;
            }
            var config = configRes.Get();

            var userRes = await GetTarget(target);

            if (userRes.IsFailure())
            {
                return;
            }
            var user = userRes.Get();

            var updateEvent = await user.EditRoles(MapRoles(Context.Guild, user)(config.Roles));

            await SendChannelMessage(
                $"> **User {MentionUtils.MentionUser(user.Id)} has been jailed.** (Done by {MentionUtils.MentionUser(Context.User.Id)})");

            await _jailData.Store(Context.Guild.Id, updateEvent.ToModel());

            await SetJailDetails(updateEvent, config.LogChannel);
        }
コード例 #2
0
        private async Task <bool> ManageRR(ReactionRoleModel rrModel, string eventType)
        {
            List <IEmote> emotes = new();

            while (true)
            {
                var ruleResult = await GetReactionRole();

                if (ruleResult.IsFailure())
                {
                    return(false);
                }
                var(emote, roleManageModel) = ruleResult.Get();
                _logging.Verbose("Writing new Rule...");
                rrModel = rrModel.UpdateRRModel(emote, roleManageModel);
                emotes.Add(emote);
                var checkLoop = await GetIsThereAnotherRule();

                if (checkLoop.IsFailure())
                {
                    return(false);
                }
                if (checkLoop.Get() == false)
                {
                    break;
                }
            }

            var res =
                from title in GetRRTitle()
                from content in GetRRContent()
                select CreateReactionRoleMessageEmbed(title, content);

            var embedRes = await res;

            if (embedRes.IsFailure())
            {
                return(false);
            }

            var embed = embedRes.Get();

            _logging.Info("Created embed!");

            var msg = await Context.Guild.GetTextChannel(rrModel.ChannelId).SendMessageAsync(embed: embed);

            rrModel = rrModel with {
                MessageId = msg.Id
            };

            _logging.Info("Sent Message!");
            //await msg.RemoveAllReactionsAsync();
            await msg.AddReactionsAsync(emotes.ToArray());

            _rrService.UpsertReactionMessage(rrModel);
            await _rrRepo.AddOrUpdateReactionRole(rrModel);

            _logging.Info($"Successfully {eventType}!");
            await SendChannelMessage(
                $"> **Successfully {eventType}!**");
            await SendChannelMessage(embed : CreateReactionRoleRuleEmbed(rrModel));

            return(true);
        }
    }
コード例 #3
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));
        }