Пример #1
0
                public async Task addAssignableRole(CommandContext ctx, [Description("Discord Role to add.")] DiscordRole discordRole, [Description("Discord Emoji to assign to role.")] DiscordEmoji emoji)
                {
                    await ctx.TriggerTypingAsync();

                    AssignableRoleJson json = await GetRoleJson(ctx);

                    try
                    {
                        DiscordEmoji testEmoji = DiscordEmoji.FromGuildEmote(ctx.Client, emoji.Id);
                    }
                    catch
                    {
                        await ctx.Channel.SendMessageAsync("You can only use server emojis from a guild where wiggims bot is connected for this command, no default emojis either.");

                        return;
                    }

                    foreach (var role in json.Roles)
                    {
                        if (role.RoleId == discordRole.Id || role.EmojiId == emoji.Id)
                        {
                            await ctx.Channel.SendMessageAsync("Either that role or emoji has already been used, if you wish to remove a role and add it again please use the `w@guild role rm [Role] command`");

                            return;
                        }
                    }

                    await _assignableRoleService.AddRoleToAssignableRoles(ctx.Guild.Id, discordRole.Id, emoji.Id);

                    await ctx.Channel.SendMessageAsync($"{discordRole.Name} was added to the assignable roles list! Please not if the role is higher up than the bots role wiggims bot will not be able to assign this role. Mr_Wiggims1 hasn't figured out how to check for this yet.");
                }
Пример #2
0
            //######## Guild role Tasks ############
            public async Task <AssignableRoleJson> GetRoleJson(CommandContext ctx)
            {
                GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

                AssignableRoleJson json = JsonConvert.DeserializeObject <AssignableRoleJson>(guildPreferences.AssignableRoleJson);

                return(json);
            }
Пример #3
0
            public async Task guildInfo(CommandContext ctx)
            {
                await ctx.TriggerTypingAsync();

                AssignableRoleJson json = await GetRoleJson(ctx);

                GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

                StringBuilder sb = new StringBuilder();

                foreach (Roles role in json.Roles)
                {
                    DiscordEmoji emoji    = DiscordEmoji.FromGuildEmote(ctx.Client, role.EmojiId);
                    string       roleName = ctx.Guild.GetRole(role.RoleId).Name;

                    sb.Append(emoji + $" : {roleName}\n");
                }

                string timeoutRoleName;

                try { timeoutRoleName = ctx.Guild.GetRole(guildPreferences.TimeoutRoleId).Name; }
                catch { timeoutRoleName = "not set"; }

                var infoEmbed = new DiscordEmbedBuilder
                {
                    Title       = $"Wiggims Bot Settings for {ctx.Guild.Name}",
                    Description = "To edit any of the following settings, type `w!help guild` to see the options available.",
                    //Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url =  = ctx.Guild.IconUrl,
                    Color = DiscordColor.Orange
                };

                infoEmbed.AddField("Basic settings:",
                                   $"Spelling tracking: enabled = {guildPreferences.SpellingEnabled}. list length {guildPreferences.ErrorListLength}\n" +
                                   $"Xp earned per message: {guildPreferences.XpPerMessage} (For 10 messages within 60 seconds)\n" +
                                   $"Auto Role: Not Implemented yet\n" +
                                   $"Timeout role: {timeoutRoleName}");

                infoEmbed.AddField("Admin Settings:",
                                   $"Admin Role: Not Implemented yet\n" +
                                   $"Guild Event Notifications: Not Implemented yet\n" +
                                   $"Admin Notification Channel: Not Implemented yet\n" +
                                   $"Punish @ every ones: Not Implemented yet\n");

                infoEmbed.AddField("Roles available through `w!role join` and `w!role leave`:", sb.ToString());

                await ctx.Channel.SendMessageAsync("", embed : infoEmbed);
            }
        public async Task RemoveRoleFromAssignableRoles(ulong guildId, ulong roleId)
        {
            using var context = new RPGContext(_options);

            GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false);

            AssignableRoleJson roleArray = JsonConvert.DeserializeObject <AssignableRoleJson>(guildPreferences.AssignableRoleJson);

            int roleIndex = roleArray.Roles.FindIndex(x => x.RoleId == roleId);

            roleArray.Roles.RemoveAt(roleIndex);

            string newRoleArray = JsonConvert.SerializeObject(roleArray);

            guildPreferences.AssignableRoleJson = newRoleArray;

            context.GuildPreferences.Update(guildPreferences);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
        public async Task AddRoleToAssignableRoles(ulong guildId, ulong roleId, ulong emojiId)
        {
            using var context = new RPGContext(_options);

            GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false);

            AssignableRoleJson roleArray = JsonConvert.DeserializeObject <AssignableRoleJson>(guildPreferences.AssignableRoleJson);

            Roles roleToAdd = new Roles {
                RoleId = roleId, EmojiId = emojiId
            };

            roleArray.Roles.Add(roleToAdd);

            string newRoleArray = JsonConvert.SerializeObject(roleArray);

            guildPreferences.AssignableRoleJson = newRoleArray;

            context.GuildPreferences.Update(guildPreferences);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Пример #6
0
                public async Task RemoveAssignableRole(CommandContext ctx, [Description("Discord Role to remove.")] DiscordRole discordRole)
                {
                    await ctx.TriggerTypingAsync();

                    AssignableRoleJson json = await GetRoleJson(ctx);

                    if (!json.Roles.Exists(x => x.RoleId == discordRole.Id))
                    {
                        throw new Exception("This role does not exist in the list for this command.");
                    }

                    try
                    {
                        await _assignableRoleService.RemoveRoleFromAssignableRoles(ctx.Guild.Id, discordRole.Id);

                        await ctx.Channel.SendMessageAsync($"{discordRole.Name} was removed from the assignable roles list!");
                    }
                    catch
                    {
                        await ctx.Channel.SendMessageAsync($"There was an issue removing {discordRole.Name} from the assignable roles list.");
                    }
                }
Пример #7
0
            public async Task leave(CommandContext ctx)
            {
                await ctx.TriggerTypingAsync();

                AssignableRoleJson json = await GetRoleJson(ctx);

                DiscordEmoji doneEmoji = DiscordEmoji.FromName(ctx.Client, ":white_check_mark:");

                if (json.Roles.Count() == 0)
                {
                    await ctx.Channel.SendMessageAsync("There are no roles in the assignable roles list. Please ask your administrator to add roles, using the `w!admin addAssignableRole [@DiscordRole] [Emoji]`.");

                    return;
                }

                TimeSpan timeSpan = TimeSpan.FromSeconds(60);

                var joinEmbed = new DiscordEmbedBuilder
                {
                    Title     = "Would you like to stop receiving pings for specific games?",
                    Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail {
                        Url = ctx.Member.AvatarUrl
                    },
                    Color       = ctx.Member.Color,
                    Description = $"Click the icons for the games that you do not wish to play anymore (only after all emojis have appeared).\nAfter 60 seconds your role changes will be applied.\n\nThis command does not allow you to join the role, if you wish to join a role please use the `w!role join` command."
                };

                StringBuilder sb = new StringBuilder();

                foreach (Roles role in json.Roles)
                {
                    try
                    {
                        DiscordEmoji emoji    = DiscordEmoji.FromGuildEmote(ctx.Client, role.EmojiId);
                        string       roleName = ctx.Guild.GetRole(role.RoleId).Name;

                        sb.Append(emoji + $" : {roleName}\n");
                    }
                    catch (Exception e)
                    {
                        await ctx.Channel.SendMessageAsync(ctx.Guild.GetRole(role.RoleId).Name + "Could not be processed");

                        Console.WriteLine(e.Message);
                    }
                }

                joinEmbed.AddField("Roles:", sb.ToString());

                var joinMessage = await ctx.Channel.SendMessageAsync(embed : joinEmbed).ConfigureAwait(false);

                var userid = ctx.Member.Id;

                foreach (var role in json.Roles)
                {
                    DiscordEmoji emoji = DiscordEmoji.FromGuildEmote(ctx.Client, role.EmojiId);
                    await joinMessage.CreateReactionAsync(emoji);
                }

                //await joinMessage.CreateReactionAsync(doneEmoji);

                var interactivity = ctx.Client.GetInteractivity();

                var result = await interactivity.CollectReactionsAsync(joinMessage, timeSpan);

                var distinctResult = result.Distinct().Where(x => x.Users.First() == ctx.User);

                StringBuilder sb2 = new StringBuilder();

                foreach (var selection in distinctResult)
                {
                    ulong reactionId = selection.Emoji.Id;

                    try
                    {
                        var index = json.Roles.FindIndex(x => x.EmojiId == reactionId);
                        await ctx.Member.RevokeRoleAsync(ctx.Guild.GetRole(json.Roles[index].RoleId));

                        sb2.Append($"\"{ctx.Guild.GetRole(json.Roles[index].RoleId).Name}\"\n");
                    }
                    catch { }
                }

                await joinMessage.DeleteAsync();

                await ctx.Channel.SendMessageAsync($"{ctx.User.Username} has left the following roles:\n```json\n{sb2}\n```");
            }