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);
        }
    }
Exemplo n.º 2
0
        private async Task <bool> SetupRR()
        {
            var modelResult = await CheckStaffAndRetrieveModel();

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

            _logging.Info($"{Context.User.Username}#{Context.User.Discriminator} in Guild {Context.Guild.Name}({Context.Guild.Id}) calling Setup Linked RR...");
            await SendChannelMessage(
                $"**Setting up linked reaction role...** (Called by {MentionUtils.MentionUser(Context.User.Id)})");

            //TODO List all the options
            var result =
                from name in GetRRName()
                from channel in GetRRChannel()
                from shouldRemove in GetShouldRRBeRemoved()
                from shouldLog in GetShouldRRBeLogged()
                from rrId in GetRRStorageKey()
                select new ReactionRoleModel
                (
                    name: name,
                    channelId: channel,
                    guildId: Context.Guild.Id,
                    messageId: 0,
                    rule: new ReverseRuleModel(new ReactionRoleConfig(shouldRemove, shouldLog, false, rrId, name))
                );

            var rr = await result;

            if (rr.IsFailure())
            {
                return(false);
            }
            var rrModel = rr.Get();

            var emoteTask = GetEmote();
            var emoteRes  = await emoteTask;

            if (emoteRes.IsFailure())
            {
                return(false);
            }
            var emote = emoteRes.Get();

            rrModel = rrModel.WithEmoteLinked(emote.Name);

            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.AddReactionAsync(emote);

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

            _logging.Info("Successfully completed Linked RR setup!");
            await SendChannelMessage(
                $"> **Sucessfully completed Linked Reaction Role setup!**");

            return(true);
        }
    }