Ejemplo n.º 1
0
        private async Task CreateMessageAsync(CommandContext context, ActiveMultiRoleCreation creation)
        {
            IUserMessage message = await context.Channel.SendMessageAsync(creation.Message);

            Entries.Add(new MultiRoleEntry(context, message.Id, creation.EmoteStringRolePairs));
            Save();
            foreach (KeyValuePair <IEmote, ulong> pair in creation.EmoteRolePairs)
            {
                await message.AddReactionAsync(pair.Key);
            }
        }
Ejemplo n.º 2
0
        private async Task ClearAsync(int index)
        {
            ActiveMultiRoleCreation creation = ActiveCreations[index];

            foreach (IUserMessage message in creation.MessagesToDelete)
            {
                try
                {
                    await message.DeleteAsync();
                }
                catch { } // has no right to delete, or the message's already deleted
            }
            ActiveCreations.RemoveAt(index);
        }
Ejemplo n.º 3
0
        public bool StartInformationFetching(ICommandContext Context)
        {
            if (GetCreation(Context) > -1)
            {
                return(false);
            }

            ActiveMultiRoleCreation creation = new ActiveMultiRoleCreation(Context);

            creation.MessagesToDelete.Add(Context.Message);
            ActiveCreations.Add(creation);

            return(true);
        }
Ejemplo n.º 4
0
        private async Task DiscordMessageReceived(SocketMessage msg)
        {
            if (!(msg is SocketUserMessage message) || message.Author.IsBot)
            {
                return;
            }

            CommandContext context = new CommandContext(Global.Client, message);

            if (context.Guild == null || !Global.IsAdminOrHigher(message.Author.Id, context.Guild.Id))
            {
                return;
            }

            int index = GetCreation(context);

            if (index > -1)
            {
                ActiveMultiRoleCreation creation = ActiveCreations[index];
                if (creation.MessagesToDelete[0].Id == message.Id)
                {
                    return;
                }


                LanguageEntry language = context.GetSettings().GetLanguage();

                creation.MessagesToDelete.Add(message);

                switch (creation.State)
                {
                case CreationState.WaitMessage:
                    creation.Message = message.Content;
                    creation.MessagesToDelete.Add(await context.Channel.SendMessageAsync(language.GetEntry("MultiRoleSystem:RequestEmotes")));
                    creation.State = CreationState.WaitEmotes;
                    break;

                case CreationState.WaitEmotes:
                    if (message.Content.Equals("no", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (creation.EmoteRolePairs.Count == 0)
                        {
                            creation.MessagesToDelete.Add(await context.Channel.SendMessageAsync(language.GetEntry("MultiRoleSystem:MinOne")));
                            break;
                        }
                        await ClearAsync(index);
                        await CreateMessageAsync(context, creation);

                        return;
                    }
                    else if (message.Content.Equals("cancel", StringComparison.InvariantCultureIgnoreCase))
                    {
                        await ClearAsync(index);

                        return;
                    }
                    else
                    {
                        string          text    = message.Content;
                        MatchCollection matches = RoleRegex.Matches(text);

                        if (matches.Count != 1)
                        {
                            creation.MessagesToDelete.Add(await context.Channel.SendMessageAsync(language.GetEntry("MultiRoleSystem:InvalidFormat")));
                            break;
                        }
                        Match roleMatch = matches[0];
                        text = text.Remove(roleMatch.Index, roleMatch.Length).Trim(' ');
                        IRole role = null;

                        if (ulong.TryParse(roleMatch.Groups[1].Value, out ulong roleId))
                        {
                            role = context.Guild.GetRole(roleId);
                        }

                        if (role == null)
                        {
                            creation.MessagesToDelete.Add(await context.Channel.SendMessageAsync(language.GetEntry("MultiRoleSystem:CouldntGetRole")));
                            break;
                        }

                        IEmote emote = null;

                        try
                        {
                            if (Emote.TryParse(text, out Emote e))
                            {
                                if (await context.Guild.GetEmoteAsync(e.Id) != null)
                                {
                                    emote = e;
                                }
                            }
                            else
                            {
                                try
                                {
                                    emote = new Emoji(text);
                                }
                                catch { }
                            }
                        }
                        catch { }

                        if (emote == null)
                        {
                            creation.MessagesToDelete.Add(await context.Channel.SendMessageAsync(language.GetEntry("MultiRoleSystem:CouldntCreateEmote")));
                        }
                        else
                        {
                            creation.EmoteRolePairs.Add(emote, role.Id);
                            creation.MessagesToDelete.Add(await context.Channel.SendMessageAsync(language.GetEntry("MultiRoleSystem:EmoteAdded")));
                        }
                    }
                    break;
                }

                ActiveCreations[index] = creation;
            }
        }