public Task blacklistAdd(params string[] words) { guildData d = MongoUtil.getGuildData(Context.Guild.Id); d.blacklistedWords.AddRange(words); MongoUtil.updateGuildData(d); return(Task.CompletedTask); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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."); } }
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!"); }