示例#1
0
        public Task blacklistAdd(params string[] words)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            d.blacklistedWords.AddRange(words);
            MongoUtil.updateGuildData(d);
            return(Task.CompletedTask);
        }
示例#2
0
 private Task UserLeft(SocketGuildUser user)
 {
     #region Leave message
     guildData   d = MongoUtil.getGuildData(user.Guild.Id);
     SocketGuild g = client.GetGuild(user.Guild.Id);
     g.SystemChannel.SendMessageAsync(d.joinMsg);
     #endregion
     return(Task.CompletedTask);
 }
示例#3
0
        public Task setCmdPrefix(string p)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            d.prefix = p;
            MongoUtil.updateGuildData(d);
            Context.Guild.CurrentUser.ModifyAsync(c => c.Nickname = $"OpenUtil ({p})");
            Context.Channel.SendMessageAsync($"Set prefix to {p}");
            return(Task.CompletedTask);
        }
示例#4
0
        public Task blacklistRemove(params string[] words)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            foreach (string word in words)
            {
                d.blacklistedWords.Remove(word);
            }
            MongoUtil.updateGuildData(d);
            return(Task.CompletedTask);
        }
示例#5
0
        private async Task helpCommand(string command)
        {
            IReadOnlyCollection <CommandInfo> l = await _commandService.GetExecutableCommandsAsync(Context, null);

            string prefix = Backbone.DEFAULT_PREFIX;

            try
            {
                guildData d = MongoUtil.getGuildData(Context.Guild.Id, false);
                prefix = d.prefix;
            }
            catch
            {
                prefix = Backbone.DEFAULT_PREFIX;
            }
            CommandInfo cmd           = null;
            string      CommandString = command;

            if (CommandString.StartsWith(prefix))
            {
                CommandString = CommandString.Substring(3);
            }
            if (l.Where(item => item.Aliases.Contains(CommandString) || item.Name == CommandString).Count() > 0)
            {
                cmd = l.Where(item => item.Aliases.Contains(CommandString) || item.Name == CommandString).First();
            }
            else
            {
                await Context.Channel.SendMessageAsync("Command " + CommandString + " not found.");

                return;
            }

            string e    = "**Help for " + prefix + cmd.Name + " ";
            string desc = ">>> ";

            foreach (ParameterInfo p in cmd.Parameters)
            {
                desc += "**" + p.Name + "**\n```Summary: " + p.Summary;
                if (p.DefaultValue != null)
                {
                    e    += "[" + p.Name + "=" + p.DefaultValue + "] ";
                    desc += "\nDefaults to: " + p.DefaultValue.ToString();
                }
                else
                {
                    e += "<" + p.Name + "> ";
                }
                desc += "\nType: " + p.Type.ToString() + "\n" + "```";
            }
            e += "**";
            await Context.Channel.SendMessageAsync(e + "\n" + desc);
        }
示例#6
0
        public Task setMutedRole(ulong RoleId = 0)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            if (Context.Guild.GetRole(RoleId) == null)
            {
                Context.Channel.SendMessageAsync("Role not found.");
                return(Task.CompletedTask);
            }
            d.mutedRole = RoleId;
            MongoUtil.updateGuildData(d);
            return(Task.CompletedTask);
        }
示例#7
0
        public Task getAutorole()
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            if (d.autoRole != null)
            {
                Context.Channel.SendMessageAsync($"Autorole is currently set to: **{d.autoRole.Name}**");
            }
            else
            {
                Context.Channel.SendMessageAsync("Autorole is currently not enabled on this server");
            }
            return(Task.CompletedTask);
        }
示例#8
0
 private Task UserJoined(SocketGuildUser user)
 {
     #region Autorole
     guildData d = MongoUtil.getGuildData(user.Guild.Id);
     if (d.autoRole != null)
     {
         user.AddRoleAsync(d.autoRole);
     }
     #endregion
     #region Join message
     SocketGuild g = client.GetGuild(user.Guild.Id);
     g.SystemChannel.SendMessageAsync(d.joinMsg);
     #endregion
     return(Task.CompletedTask);
 }
示例#9
0
        public Task ignorechAdd(IMessageChannel channel = null)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            if (channel == null)
            {
                d.ignoredChannelIds.Add(Context.Channel.Id);
            }
            else
            {
                d.ignoredChannelIds.Add(channel.Id);
            }
            MongoUtil.updateGuildData(d);
            return(Task.CompletedTask);
        }
示例#10
0
        public Task ignorechRemove(IMessageChannel channel = null)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            if (channel == null)
            {
                d.ignoredChannelIds.Remove(Context.Channel.Id);
            }
            else
            {
                //No need to check validity
                d.ignoredChannelIds.Remove(channel.Id);
            }
            MongoUtil.updateGuildData(d);
            return(Task.CompletedTask);
        }
示例#11
0
        public Task clearWarnings(SocketUser user)
        {
            guildData data = MongoUtil.getGuildData(Context.Guild.Id);

            if (!data.manualModEnabled)
            {
                Context.Channel.SendMessageAsync("Please enable the moderation module to use this command.");
                return(Task.CompletedTask);
            }
            if (data.warnings.ContainsKey(user.Id))
            {
                data.warnings.Remove(user.Id);
            }
            MongoUtil.updateGuildData(data);
            Context.Channel.SendMessageAsync($"Cleared user {user.Username}#{user.Discriminator} of all warnings/infractions.");
            return(Task.CompletedTask);
        }
示例#12
0
        public Task setAutomod(bool enable)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            d.automodEnabled = enable;
            MongoUtil.updateGuildData(d);
            if (enable)
            {
                Context.Channel.SendMessageAsync($"Automod enabled.\n" +
                                                 $"Add/Remove blacklisted words with `{d.prefix}blacklist-add` and `{d.prefix}blacklist-remove`\n" +
                                                 $"Add/Remove channels that automod should ignore with `{d.prefix}ignorech-add` and `{d.prefix}ignorech-remove`");
            }
            else
            {
                Context.Channel.SendMessageAsync("Automod disabled.");
            }
            return(Task.CompletedTask);
        }
示例#13
0
        public Task setAutorole(
            [Summary("Id of the role to automatically assign. If left blank it will disable autorole")] ulong roleId  = 0,
            [Summary("Whether the bot should make sure all users have the role, or only give it once")] bool maintain = false)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            if (roleId == 0)
            {
                d.autoRole = null;
                Context.Channel.SendMessageAsync("Autorole disabled");
                return(Task.CompletedTask);
            }
            d.autoRole     = Context.Guild.GetRole(roleId);
            d.maintainRole = maintain;
            MongoUtil.updateGuildData(d);
            Context.Channel.SendMessageAsync($"Set autorole to **{d.autoRole.Name}**");
            return(Task.CompletedTask);
        }
示例#14
0
        public Task userWarns(SocketUser user)
        {
            guildData data = MongoUtil.getGuildData(Context.Guild.Id);

            if (!data.manualModEnabled)
            {
                Context.Channel.SendMessageAsync("Please enable the moderation module to use this command.");
                return(Task.CompletedTask);
            }
            if (data.warnings.ContainsKey(user.Id))
            {
                Context.Channel.SendMessageAsync($"User {user.Username}#{user.Discriminator} has {data.warnings[user.Id]} warnings");
            }
            else
            {
                Context.Channel.SendMessageAsync($"User {user.Username}#{user.Discriminator} has no warnings.");
            }
            return(Task.CompletedTask);
        }
示例#15
0
        public Task addRoleCmd(string cmd, ulong roleId)
        {
            guildData find = MongoUtil.getGuildData(Context.Guild.Id);

            if (find.roleCmds.ContainsKey(cmd))
            {
                Context.Channel.SendMessageAsync("There is already a role command attatched to that. Please try a different one.");
            }
            else   //Allow multiple commands to point to one role
            {
                IRole r = Context.Guild.GetRole(roleId);
                if (r == null)
                {
                    Context.Channel.SendMessageAsync("Role not found!");
                    return(Task.CompletedTask);
                }
                find.roleCmds.Add(cmd, r);
            }
            MongoUtil.updateGuildData(find);
            return(Task.CompletedTask);
        }
示例#16
0
        public Task warnUser(SocketUser user)
        {
            guildData data = MongoUtil.getGuildData(Context.Guild.Id);

            if (!data.manualModEnabled)
            {
                Context.Channel.SendMessageAsync("Please enable the moderation module to use this command.");
                return(Task.CompletedTask);
            }
            if (data.warnings.ContainsKey(user.Id))
            {
                data.warnings[user.Id]++;
            }
            else
            {
                data.warnings.Add(user.Id, 1);
            }
            MongoUtil.updateGuildData(data);
            Context.Channel.SendMessageAsync($"Warned user {user.Username}#{user.Discriminator}.\nThey now have {data.warnings[user.Id]} warnings.");
            return(Task.CompletedTask);
        }
示例#17
0
        public Task roleAssign(string role = null)
        {
            guildData d = MongoUtil.getGuildData(Context.Guild.Id);

            if (role == null)
            {
                string output = "```";
                foreach (string s in d.roleCmds.Keys.ToList())
                {
                    output += s + "\n";
                }
                output += "```";
                Context.Channel.SendMessageAsync("Here are the current role commands:\n" + output);
            }
            else
            {
                IRole           r;
                SocketGuildUser s = Context.User as SocketGuildUser;
                if (!d.roleCmds.TryGetValue(role, out r))
                {
                    Context.Channel.SendMessageAsync("Role not found.");
                    return(Task.CompletedTask);
                }
                if (s.Roles.Contains(r))
                {
                    s.RemoveRoleAsync(r);
                    Context.Channel.SendMessageAsync("Role removed.");
                }
                else
                {
                    s.AddRoleAsync(r);
                    Context.Channel.SendMessageAsync("Role added.");
                }
            }
            return(Task.CompletedTask);
        }
示例#18
0
        public Task muteUser(SocketUser user)
        {
            guildData data = MongoUtil.getGuildData(Context.Guild.Id);

            if (!data.manualModEnabled)
            {
                Context.Channel.SendMessageAsync("Please enable the moderation module to use this command.");
                return(Task.CompletedTask);
            }
            if (data.mutedRole == 0)
            {
                Context.Channel.SendMessageAsync($"Muted role not set! Set it with {data.prefix}set-mutedrole");
                return(Task.CompletedTask);
            }
            SocketGuildUser sg = user as SocketGuildUser;

            if (sg == null)
            {
                Context.Channel.SendMessageAsync("This command can only work in servers");
                return(Task.CompletedTask);
            }
            sg.AddRoleAsync(Context.Guild.GetRole(data.mutedRole));
            return(Task.CompletedTask);
        }
示例#19
0
        public async Task HandleCommandAsync(SocketMessage messageParam)
        {
            // Don't process the command if it was a system message
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }

            // Create a WebSocket-based command context based on the message
            var context = new SocketCommandContext(_client, message);

            guildData d = MongoUtil.getGuildData(context.Guild.Id);

            // Create a number to track where the prefix ends and the command begins
            int    argPos = Backbone.DEFAULT_PREFIX.Length;
            string p      = Backbone.DEFAULT_PREFIX;

            if (d != null)
            {
                //Command
                argPos = d.prefix.Length;
                p      = d.prefix;
            }

            // Determine if the message is a command based on the prefix and make sure no bots trigger commands
            if (!(message.HasStringPrefix(p, ref argPos) ||
                  message.HasMentionPrefix(_client.CurrentUser, ref argPos)) ||
                message.Author.IsBot)
            {
                //Automod

                /**
                 * Check if Automod is enabled,
                 * the current channel is not meant to be ignored,
                 * and then if the message is blacklisted
                 */
                if (d.automodEnabled &&
                    !d.ignoredChannelIds.Contains(context.Channel.Id) &&
                    d.illegalMsg(message.Content))
                {
                    await message.DeleteAsync();

                    return;
                }

                return;
            }
            else
            {
                Console.WriteLine($"Command Received: {message.Content}");
            }


            // Execute the command with the command context we just
            // created, along with the service provider for precondition checks.

            // Keep in mind that result does not indicate a return value
            // rather an object stating if the command executed successfully.
            var result = await _commands.ExecuteAsync(
                context : context,
                argPos : argPos,
                services : null);

            // Optionally, we may inform the user if the command fails
            // to be executed; however, this may not always be desired,
            // as it may clog up the request queue should a user spam a
            // command.
            if (!result.IsSuccess)
            {
                await context.Channel.SendMessageAsync($"An error ocurred: ```{result.ErrorReason}```\nPlease report this at" + @"`https://github.com/Bytestorm1/OpenUtil/issues`" + "with screenshots if possible.");
            }
        }
示例#20
0
        public async Task help(string commandString = "not_actually_default_ignore_this")
        {
            if (commandString != "not_actually_default_ignore_this")
            {
                await helpCommand(commandString);

                return;
            }
            IReadOnlyCollection <CommandInfo> l = await _commandService.GetExecutableCommandsAsync(Context, null);

            string prefix = Backbone.DEFAULT_PREFIX;

            try
            {
                guildData d = MongoUtil.getGuildData(Context.Guild.Id, false);
                prefix = d.prefix;
            }
            catch {
                prefix = Backbone.DEFAULT_PREFIX;
            }
            List <string> s = new List <string>();

            foreach (CommandInfo cmd in l)
            {
                string e = "**" + prefix + cmd.Name + " ";
                foreach (ParameterInfo p in cmd.Parameters)
                {
                    if (p.DefaultValue != null)
                    {
                        e += "[" + p.Name + "=" + p.DefaultValue + "] ";
                    }
                    else
                    {
                        e += "<" + p.Name + "> ";
                    }
                }
                e += "**";
                if (cmd.Summary != null)
                {
                    e += "\n```" + cmd.Summary + "```";
                }
                s.Add(e);
            }
            //s.Add("If you are seeing this line, send a screennshot of this command to the bot dev.");
            List <string> output = new List <string>();
            //s.ForEach(item => output += item);
            int i = 0;

            foreach (string c in s)
            {
                if (output.Count == 0 || i >= output.Count)
                {
                    output.Add("");
                }
                if ((output[i] + c + "\n").Length > 2000)
                {
                    i++;
                    if (output.Count == 0 || i >= output.Count)
                    {
                        output.Add("");
                    }
                }
                output[i] += c + "\n";
            }
            IDMChannel channel = await Context.User.GetOrCreateDMChannelAsync();

            foreach (string ae in output)
            {
                await channel.SendMessageAsync(">>> " + ae);
            }
            //await Context.Channel.SendMessageAsync(output);
            await Context.Channel.SendMessageAsync("Sent you a DM!");
        }
示例#21
0
        public override async Task OperateCommand(CommandContext ctx, params string[] args)
        {
            await base.OperateCommand(ctx, args);

            string    subCommand = args[0];
            guildData data       = Utils.returnGuildData(ctx.Guild.Id);

            switch (subCommand.ToLower())
            {
            case "play":
                //Play the tunes!
                await VoiceJoin(ctx);

                //We need to download the spotify song or whatever
                if (args[1] != null)
                {
                    //Start to play the song
                    if (args[1].Contains("youtube") || args[1].Contains("youtu.be"))
                    {
                    }
                    else if (args[1].Contains("spotify"))
                    {
                        //Initialise the spotify bot if has not done yet!
                        if (api == null)
                        {
                            CredentialsAuth auth  = new CredentialsAuth("7c09a36e2ef84c2abc068c8979103d17", "d21bc05a3f604089b176e3b3e5975e0b");
                            Token           token = await auth.GetToken();

                            api = new SpotifyWebAPI
                            {
                                AccessToken = token.AccessToken,
                                TokenType   = token.TokenType
                            };
                        }

                        string uriCode = null;
                        Uri    uri     = new UriBuilder(args[1]).Uri;

                        if (args[1] != null)
                        {
                            //Get the spotify track from url or the uri code
                            uriCode = uri.Segments[2];
                        }

                        if (uriCode != null)
                        {
                            if (uri.Segments[1] == "track")
                            {
                                FullTrack track = await api.GetTrackAsync(uriCode);

                                if (track.Artists != null)
                                {
                                    List <string> artists = new List <string>();
                                    foreach (SimpleArtist artist in track.Artists)
                                    {
                                        artists.Add(artist.Name);
                                    }
                                    string connectArtist = string.Join(",", artists.ToArray());
                                    await ctx.RespondAsync("Playing: " + track.Name + " By: " + connectArtist);
                                }
                                if (track.HasError())
                                {
                                    await ctx.RespondAsync("The track when playing had an issue!");
                                }
                            }
                            else if (uri.Segments[1] == "playlist")
                            {
                                //Playlist
                                FullPlaylist list = await api.GetPlaylistAsync(uriCode);

                                await ctx.RespondAsync("Playing: " + list.Name);

                                if (list.HasError())
                                {
                                    await ctx.RespondAsync("The playlist had and issue");
                                }
                            }
                        }
                        else
                        {
                            await ctx.RespondAsync("Invalid url or uri code");
                        }
                    }
                }
                else
                {
                    await ctx.RespondAsync("No song link was defined!");
                }
                break;

            case "stop":
                //Stop the tunes!

                break;

            case "leave":
            case "fuckoff":
                //Leave the channel forcefully!
                await VoiceLeave(ctx);

                break;

            case "autoleave":
                //Set if the bot should automatically leave the voice channel when no one is in the voice channel
                if (data.autoSongLeave == false)
                {
                    data.autoSongLeave = true;
                    await ctx.RespondAsync("This bot will leave the party when everyone else has finished!");
                }
                else if (data.autoSongLeave == true)
                {
                    data.autoSongLeave = false;
                    await ctx.RespondAsync("This bot will keep on partying!");
                }
                break;

            case "loop":
                //loop the song that is currently playing
                if (data.loopSong == false)
                {
                    data.loopSong = true;
                    await ctx.RespondAsync("Looping Song !");
                }
                else if (data.loopSong == true)
                {
                    data.loopSong = false;
                    await ctx.RespondAsync("Not Looping Song!");
                }
                break;

            default:
            case "help":
                //Show the help on it.
                Dictionary <string, string> argumentsHelp = new System.Collections.Generic.Dictionary <string, string>();
                argumentsHelp.Add(";;song play", "specify a song right after play with a space then this bot will play or specify a link (overrides queue)");
                argumentsHelp.Add(";;song stop", "stop whatever is playing");
                argumentsHelp.Add(";;song leave", "forces the bot to leave the current voice channel");
                argumentsHelp.Add(";;song autoleave", "turns on auto leave the bot will leave the channel when no one is present");
                argumentsHelp.Add(";;song loop", "loops the current song and disables queue");
                DiscordEmbed embedHelp = JosephineEmbedBuilder.CreateEmbedMessage(ctx, "Sub-Commands", "for ';;announce set'", null, JosephineBot.defaultColor, argumentsHelp, false);
                await ctx.RespondAsync("Go to http://discord.rickasheye.xyz/ for all sub-commands", false, embedHelp);

                break;
            }
        }