Esempio n. 1
0
        public async Task SetMessage([Remainder] string mess)
        {
            var db      = new BotBaseContext();
            var message = db.Message.AsQueryable().Where(msg => msg.UserId == Context.User.Id).FirstOrDefault();
            var user    = db.User.AsQueryable().Where(usr => usr.UserId == Context.User.Id).FirstOrDefault();

            if (user == null)
            {
                db.Add(new User {
                    UserId = Context.User.Id, Name = Context.User.Username, Number = long.Parse(Context.User.Discriminator)
                });
            }
            else
            {
                user.Name   = Context.User.Username;
                user.Number = long.Parse(Context.User.Discriminator);
            }
            if (message == null)
            {
                db.Add(new Message {
                    UserId = Context.User.Id, Message1 = mess
                });
            }
            else
            {
                await ReplyAsync("Replacing old message:");
                await ReplyAsync(message.Message1);

                message.Message1 = mess;
            }
            db.SaveChanges();
            await ReplyAsync("Message Added!");
        }
Esempio n. 2
0
        public async Task ToggleSignature([Remainder] string sig = "")
        {
            var db        = new BotBaseContext();
            var signature = db.Signature.AsQueryable().Where(s => s.UserId == Context.User.Id).FirstOrDefault();
            var user      = db.User.AsQueryable().Where(usr => usr.UserId == Context.User.Id).FirstOrDefault();

            sig = sig.Replace("<", string.Empty);
            sig = sig.Replace(">", string.Empty);
            if (user == null)
            {
                db.Add(new User {
                    UserId = Context.User.Id, Name = Context.User.Username, Number = long.Parse(Context.User.Discriminator)
                });
            }
            else
            {
                user.Name   = Context.User.Username;
                user.Number = long.Parse(Context.User.Discriminator);
            }
            if (sig == "")
            {
                if (signature == null)
                {
                    await ReplyAsync("User does not have a signature to remove. Doing nothing.");

                    return;
                }
                db.Signature.Remove(signature);
            }
            else
            {
                if (signature == null)
                {
                    db.Add(new Signature {
                        UserId = Context.User.Id, Signature1 = sig
                    });
                }
                else if (signature.Signature1 == sig)
                {
                    db.Signature.Remove(signature);
                }
                else
                {
                    signature.Signature1 = sig;
                }
            }
            db.SaveChanges();
            await ReplyAsync("Signature updated.");
        }
Esempio n. 3
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. 4
0
        private Task OnReady()
        {
            var db     = new BotBaseContext();
            var config = db.Configuration.AsQueryable().Where(cfg => cfg.Name == configName).First();

            client.SetGameAsync(config.Prefix + "commands");
            db.Command.RemoveRange(db.Command);
            db.CommandAlias.RemoveRange(db.CommandAlias);
            foreach (Discord.Commands.CommandInfo c in this.commands.Commands)
            {
                if (c.Module.Name != "Hidden")
                {
                    if (c.Aliases.Count > 1)
                    {
                        foreach (string alias in c.Aliases)
                        {
                            if (alias != c.Name)
                            {
                                db.Add(new CommandAlias {
                                    Alias = alias, Command = c.Name
                                });
                            }
                        }
                    }
                    db.Add(new Command {
                        Name = c.Name, Category = c.Module.Name, Usage = c.Remarks.Replace("-c-", $"{config.Prefix}{c.Name}"), Description = c.Summary.Replace("-p-", config.Prefix)
                    });
                }
            }
            var update = db.Variable.AsQueryable().Where(V => V.Name == "lastCmdUpdateTime").FirstOrDefault();

            update.Value = DateTime.Now.ToLocalTime().ToString();
            db.SaveChanges();

            return(Task.CompletedTask);
        }
Esempio n. 5
0
        public async Task SetMessageReport([Remainder] string args = "")
        {
            var db     = new BotBaseContext();
            var config = db.ServerConfig.AsQueryable().Where(s => s.ServerId == Context.Guild.Id).FirstOrDefault();

            if (config != null)
            {
                if (config.MessageId == Context.Channel.Id)
                {
                    config.MessageId = 0;
                    await ReplyAsync($"Message deletion reports will no longer be sent in {Context.Channel.Name}");
                }
                else
                {
                    var old = await Context.Guild.GetTextChannelAsync(config.MessageId);

                    config.MessageId = Context.Channel.Id;
                    if (old != null)
                    {
                        await ReplyAsync($"Message deletion reports will no longer be sent in {old.Name}, will now be sent in {Context.Channel.Name}");
                    }
                    else
                    {
                        await ReplyAsync($"Message deletion reports will now be sent in {Context.Channel.Name}");
                    }
                }
            }
            else
            {
                db.Add(new ServerConfig {
                    ServerId = Context.Guild.Id, MessageId = Context.Channel.Id
                });
                await ReplyAsync($"Message deletion reports will now be sent in {Context.Channel.Name}");
            }
            db.SaveChanges();
        }
Esempio n. 6
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);
                }
            }
        }
Esempio n. 7
0
        public async Task PlaceReactMessage([Remainder] string command = "")
        {
            var db     = new BotBaseContext();
            var config = db.ServerConfig.AsQueryable().Where(s => s.ServerId == Context.Guild.Id).FirstOrDefault();

            if (command == "-d")
            {
                if (config != null && config.ReactMessageId != 0 && config.ReactChannelId != 0)
                {
                    var channel = await Context.Guild.GetTextChannelAsync(config.ReactChannelId);

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

                    await msg.DeleteAsync();

                    config.ReactChannelId = 0;
                    config.ReactMessageId = 0;
                    db.SaveChanges();
                    await ReplyAsync("Message removed. Any withstanding roles will remain.");

                    return;
                }
                await ReplyAsync("Message does not exist, or cannot be found. Not deleting");

                return;
            }

            var message = await ReplyAsync("", false, BuildReactMessage(Context.Guild));

            if (config == null)
            {
                db.Add(new ServerConfig {
                    ServerId = Context.Guild.Id, ReactMessageId = message.Id, ReactChannelId = message.Channel.Id
                });
            }
            else
            {
                if (config.ReactChannelId != 0)
                {
                    var channel = await Context.Guild.GetTextChannelAsync(config.ReactChannelId);

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

                    await msg.DeleteAsync();
                }

                config.ReactMessageId = message.Id;
                config.ReactChannelId = message.Channel.Id;
            }
            db.SaveChanges();

            var roles = db.ReactRole.AsQueryable().Where(r => r.ServerId == Context.Guild.Id).DefaultIfEmpty();

            foreach (var role in roles)
            {
                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(role.Emote, @"(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])"))
                {
                    Emoji dEmoji = new Emoji(role.Emote);
                    await message.AddReactionAsync(dEmoji);
                }
                else
                {
                    Emote dEmote = Emote.Parse(role.Emote);
                    await message.AddReactionAsync(dEmote);
                }
            }
        }
Esempio n. 8
0
        private async Task CheckKeyword(SocketUserMessage msg)
        {
            var db     = new BotBaseContext();
            var react  = db.ReactionBan.AsQueryable().AsQueryable().Where(c => c.ChannelId == msg.Channel.Id).FirstOrDefault();
            var config = db.Configuration.AsQueryable().Where(cfg => cfg.Name == Program.configName).First();

            if (react != null)
            {
                return;
            }
            string words = msg.Content.ToString();

            words = words.Replace("*", "");
            words = words.Replace("_", "");
            words = words.ToLower();

            if (hasString(words, @"delete? this"))
            {
                await msg.Channel.SendFileAsync("Media/deletthis.jpg");
            }

            if (words.Equals(":o") || words.Equals(":0"))
            {
                await msg.Channel.SendMessageAsync(":O");
            }

            if (hasString(words, "nani"))
            {
                await msg.Channel.SendFileAsync("Media/nani.jpg");

                await msg.Channel.SendMessageAsync("**NANI?!?!**");
            }

            if (hasString(words, @"be *gone,* thot"))
            {
                await msg.Channel.SendFileAsync("Media/thot.jpg");
            }

            if (hasString(words, "kms"))
            {
                await msg.Channel.SendFileAsync("Media/kms.png");
            }

            if (words.Equals("stop"))
            {
                await msg.Channel.SendFileAsync("Media/stop.png");
            }

            if (hasString(words, "bamboozle"))
            {
                await msg.Channel.SendFileAsync("Media/bamboozle.png");
            }

            if (words.ToLower().Equals("hi") || words.ToLower().Equals("hello") || words.ToLower().Equals("hey") || words.ToLower().Equals("yo") || words.ToLower().Equals("henlo") || words.ToLower().Equals("hiya") || words.ToLower().Equals("heya"))
            {
                Random rnd      = new Random();
                int    num      = rnd.Next(db.Greeting.Count()) + 1;
                var    greeting = db.Greeting.AsQueryable().AsQueryable().Where(greet => greet.Id == Convert.ToUInt64(num)).First();
                await msg.Channel.SendMessageAsync(greeting.Greeting1);
            }

            if (hasString(words, @"ah{5,}"))
            {
                await msg.Channel.SendMessageAsync("https://www.youtube.com/watch?v=yBLdQ1a4-JI");
            }

            if (hasString(words, "@here") || hasString(words, "@everyone"))
            {
                await msg.Channel.SendMessageAsync("<:ping:377208255132467233>");
            }

            if (hasString(words, "i mean") && msg.Author.Id == 150084781864910848)
            {
                var count = db.Variable.AsQueryable().AsQueryable().Where(v => v.Name == "meanCount").First();
                int num   = Convert.ToInt32(count.Value) + 1;
                count.Value = Convert.ToString(num);
                db.SaveChanges();
                await msg.Channel.SendMessageAsync("<@150084781864910848> you've said \"I mean\" " + count.Value + " times.");
            }

            if (hasString(words, "f**k y?o?u jif ?bot"))
            {
                await msg.DeleteAsync();

                await msg.Channel.SendMessageAsync("Know your place, trash.");
            }
            foreach (SocketUser mention in msg.MentionedUsers)
            {
                if (mention.Id == config.Id)
                {
                    if (words.ToLower().Contains("play despacito"))
                    {
                        await msg.Channel.SendMessageAsync("https://www.youtube.com/watch?v=kJQP7kiw5Fk");
                    }
                    else if (msg.Author.Id == 186584509226024960)
                    {
                        await msg.Channel.SendMessageAsync("you're pretty ❤");
                    }
                    else
                    {
                        await msg.Channel.SendMessageAsync("<:ping:377208255132467233>");
                    }
                }
            }

            var             channel = (SocketGuildChannel)msg.Channel;
            SocketGuildUser jifBot  = channel.Guild.GetUser(config.Id);

            foreach (SocketRole role in msg.MentionedRoles)
            {
                if (jifBot.Roles.Contains(role))
                {
                    await msg.Channel.SendMessageAsync("<:ping:377208255132467233>");

                    break;
                }
            }

            if (hasString(words, "honk"))
            {
                await msg.Channel.SendFileAsync("Media/honk.jpg");

                await msg.Channel.SendMessageAsync("**HONK**");

                var user = db.User.AsQueryable().AsQueryable().Where(user => user.UserId == msg.Author.Id).FirstOrDefault();
                var honk = db.Honk.AsQueryable().AsQueryable().Where(honk => honk.UserId == msg.Author.Id).FirstOrDefault();

                if (user == null)
                {
                    db.Add(new User {
                        UserId = msg.Author.Id, Name = msg.Author.Username, Number = long.Parse(msg.Author.Discriminator)
                    });
                }
                else
                {
                    user.Name   = msg.Author.Username;
                    user.Number = long.Parse(msg.Author.Discriminator);
                }
                if (honk == null)
                {
                    db.Add(new Honk {
                        UserId = msg.Author.Id, Count = 1
                    });
                }
                else
                {
                    honk.Count += 1;
                }
                db.SaveChanges();
            }
        }