Esempio n. 1
0
        public async Task ToggleReactions([Remainder] string args = "")
        {
            var db = new BotBaseContext();

            if (args.ToLower().Contains("all"))
            {
                var channels = db.ReactionBan.AsQueryable().Where(c => c.ServerId == Context.Guild.Id).ToList();
                if (channels.Count == 0)
                {
                    foreach (var c in await Context.Guild.GetTextChannelsAsync())
                    {
                        db.Add(new ReactionBan {
                            ChannelId = c.Id, ServerId = Context.Guild.Id, ChannelName = c.Name
                        });
                    }
                    await ReplyAsync("Reactions are now disabled for all currently available channels in the server");
                }
                else
                {
                    foreach (var c in channels)
                    {
                        db.Remove(c);
                    }
                    await ReplyAsync("Reactions are now enabled for all channels in this server");
                }
            }
            else
            {
                var channel = db.ReactionBan.AsQueryable().Where(s => s.ChannelId == Context.Channel.Id).FirstOrDefault();
                if (channel == null)
                {
                    db.Add(new ReactionBan {
                        ChannelId = Context.Channel.Id, ServerId = Context.Guild.Id, ChannelName = Context.Channel.Name
                    });
                    await ReplyAsync($"Reactions are now disabled for {Context.Channel.Name}");
                }
                else
                {
                    db.ReactionBan.Remove(channel);
                    await ReplyAsync($"Reactions are now enabled for {Context.Channel.Name}");
                }
            }
            db.SaveChanges();
        }
Esempio n. 2
0
        public async Task ReactRole(string role, string emote, [Remainder] string description = "")
        {
            // Check to ensure the role is valid
            var   db = new BotBaseContext();
            Emote dEmote;

            if (!Regex.IsMatch(role, @"[0-9]+"))
            {
                await ReplyAsync("Not a valid role");

                return;
            }
            ulong roleId = Convert.ToUInt64(Regex.Match(role, @"[0-9]+").Value);

            if (Context.Guild.Roles.Where(r => r.Id == roleId).FirstOrDefault() == null)
            {
                await ReplyAsync("Not a valid role");

                return;
            }

            var react = db.ReactRole.AsQueryable().Where(s => s.RoleId == roleId).FirstOrDefault();

            // specified to delete the react role
            if (emote == "-d")
            {
                if (react != null)
                {
                    db.Remove(react);
                    db.SaveChanges();
                    await ReplyAsync("Role removed");
                }
                else
                {
                    await ReplyAsync("Role does not exist. Not removing");

                    return;
                }
            }
            else
            {
                // Check to ensure the emote is in a valid format
                if (!Regex.IsMatch(emote, @"(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])") && !Emote.TryParse(emote, out dEmote))
                {
                    await ReplyAsync("Not a valid reaction emote");

                    return;
                }

                var rRole = db.ReactRole.AsQueryable().Where(r => r.Emote == emote && r.ServerId == Context.Guild.Id).FirstOrDefault();

                // if there exists an entry in this server with the specified emote that is not the specified role
                if (rRole != null && rRole.RoleId != roleId)
                {
                    await ReplyAsync("Emote already being used");

                    return;
                }

                // if there is no entry for this role
                else if (react == null)
                {
                    db.Add(new ReactRole {
                        RoleId = roleId, Emote = emote, Description = description, ServerId = Context.Guild.Id
                    });
                    db.SaveChanges();
                    await ReplyAsync("Role Added");

                    react = db.ReactRole.AsQueryable().Where(s => s.RoleId == roleId).FirstOrDefault();
                }

                // update emote and description
                else
                {
                    react.Emote       = emote;
                    react.Description = description;
                    db.SaveChanges();
                    await ReplyAsync($"Updated entry for <@&{react.RoleId}>");
                }
            }

            var config  = db.ServerConfig.AsQueryable().Where(s => s.ServerId == Context.Guild.Id).FirstOrDefault();
            var channel = await Context.Guild.GetTextChannelAsync(config.ReactChannelId);

            var msg = (IUserMessage)await channel.GetMessageAsync(config.ReactMessageId);

            await msg.ModifyAsync(m => m.Embed = BuildReactMessage(Context.Guild));

            var botConfig = db.Configuration.AsQueryable().Where(b => b.Name == Program.configName).First();
            var bot       = await Context.Guild.GetUserAsync(botConfig.Id);

            // Emojis and Discord Emotes are handled differently
            if (Regex.IsMatch(react.Emote, @"(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])"))
            {
                Emoji dEmoji = new Emoji(react.Emote);
                if (emote == "-d")
                {
                    await msg.RemoveReactionAsync(dEmoji, bot);
                }
                else
                {
                    await msg.AddReactionAsync(dEmoji);
                }
            }
            else
            {
                dEmote = Emote.Parse(react.Emote);
                if (emote == "-d")
                {
                    await msg.RemoveReactionAsync(dEmote, bot);
                }
                else
                {
                    await msg.AddReactionAsync(dEmote);
                }
            }
        }