public async Task SetTextIntoConfigLol([Remainder] string msg) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); var embed = new EmbedBuilder(); embed.WithDescription( $"Set this guild's leaving message to:\n\n ```{msg}```\n\nSending a test welcome message to <#{config.WelcomeChannel}>"); embed.WithColor(new Color(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3)); embed.WithFooter(Bot.Internal.Utilities.GetFormattedLocaleMsg("CommandFooter", Context.User.Username)); config.LeavingMessage = msg; GuildConfig.SaveGuildConfig(); await SendMessage(embed); if (config.WelcomeChannel != 0) { var a = config.LeavingMessage.Replace("{UserMention}", Context.User.Mention); var b = a.Replace("{ServerName}", Context.Guild.Name); var c = b.Replace("{UserName}", Context.User.Username); var d = c.Replace("{OwnerMention}", Context.Guild.Owner.Mention); var e = d.Replace("{UserTag}", Context.User.DiscriminatorValue.ToString()); var channel = Context.Guild.GetTextChannel(config.WelcomeChannel); var embed2 = new EmbedBuilder(); embed2.WithDescription(e); embed2.WithColor(new Color(config.WelcomeColour1, config.WelcomeColour2, config.WelcomeColour3)); embed2.WithFooter($"Guild Owner: {Context.Guild.Owner.Username}#{Context.Guild.Owner.Discriminator}"); embed2.WithThumbnailUrl(Context.Guild.IconUrl); await channel.SendMessageAsync("", false, embed2); } }
public async Task CreateConfigIfOneDoesntExist(ulong serverId = 0) { if (serverId == 0) { serverId = Context.Guild.Id; } var g = Program._client.GetGuild(serverId); var embed = Helpers.CreateEmbed(Context, $"Created a config for the guild `{g.Name}! ({serverId})`"); var targetConfig = GuildConfig.GetGuildConfig(serverId); var serverIds = new List <ulong>(); foreach (var server in Program._client.Guilds) { serverIds.Add(server.Id); } if (targetConfig == null && serverIds.Contains(serverId)) { GuildConfig.CreateGuildConfig(serverId); } else { embed.WithDescription( $"Couldn't create a config for {serverId}. Either they already have a config, or I don't have access to that server."); } await Helpers.SendMessage(Context, embed); }
public async Task SetRoleInConfig([Remainder] string role) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); config.SupportRole = role; GuildConfig.SaveGuildConfig(); await ReplyAsync($"`{role}` set as the role to manage tickets."); }
public async Task AddChannelToConfig(string arg) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); config.SupportChannelName = arg; GuildConfig.SaveGuildConfig(); await ReplyAsync($"{arg} set as the Support channel name."); }
public async Task AddBooleanToJson(bool arg) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); config.CanCloseOwnTicket = arg; GuildConfig.SaveGuildConfig(); var embed = Helpers.CreateEmbed(Context, $"{arg} set as the Support Ticket `CanCloseOwnTicket` option."); await Helpers.SendMessage(Context, embed); }
public async Task SendWMSGToUser() { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); var embed = new EmbedBuilder(); embed.WithDescription($"The welcome message for this server is: `{config.WelcomeMessage}`"); embed.WithColor(new Color(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3)); await SendMessage(embed); }
public static async Task GuildUtils(SocketGuild s) { var config = GuildConfig.GetGuildConfig(s.Id) ?? GuildConfig.CreateGuildConfig(s.Id); if (Config.bot.Blacklist.Contains(s.Owner.Id)) { await s.LeaveAsync(); return; } var Bots = 0; var Users = 0; foreach (var user in s.Users) { if (user.IsBot) { Bots += 1; } else { Users += 1; } } if (Bots > Users) { var greemDm = await _client.GetUser(Config.bot.BotOwner).GetOrCreateDMChannelAsync(); await greemDm.SendMessageAsync("", false, new EmbedBuilder() .WithDescription( $"Server {s.Name} is potentially harmful. They have {Bots} bots and {Users} users. Consider making the bot leave.") .WithColor(Config.bot.DefaultEmbedColour)); } var dmChannel = await s.Owner.GetOrCreateDMChannelAsync(); var embed = new EmbedBuilder(); embed.WithTitle($"Thanks for adding me to your server, {s.Owner.Username}!"); embed.WithDescription( "For quick information, visit the wiki: https://github.com/greemdotcs/greemdotcs.github.io/wiki \nNeed quick help? Visit the SIVA-dev server and create a support ticket: https://discord.gg/ubXaT6u \nTo get started, use the command `$h`. Follow that with a module to get a list of commands!"); embed.WithThumbnailUrl(s.IconUrl); embed.WithFooter("Still need help? Visit the SIVA-dev server linked above."); embed.WithColor(Config.bot.DefaultEmbedColour); await dmChannel.SendMessageAsync("", false, embed); config.GuildOwnerId = s.Owner.Id; GuildConfig.SaveGuildConfig(); }
public async Task CreateConfigsBecauseImADumbassDotExe() { foreach (var guild in Program._client.Guilds) { if (guild.Id != 405806471578648588) { GuildConfig.CreateGuildConfig(guild.Id); } } await ReplyAsync($"Successfully created configs for {Program._client.Guilds.Count - 1} servers."); }
public async Task SetGuildPrefix([Remainder] string prefix) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); var embed = new EmbedBuilder(); embed.WithDescription("Done."); embed.WithFooter(Bot.Utilities.GetFormattedLocaleMsg("CommandFooter", Context.User.Username)); embed.WithColor(new Color(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3)); config.CommandPrefix = prefix; GuildConfig.SaveGuildConfig(); await SendMessage(embed); }
public async Task SetIdIntoConfig(SocketGuildChannel chnl) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); var embed = new EmbedBuilder(); embed.WithDescription($"Set this guild's welcome channel to #{chnl}."); embed.WithColor(new Color(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3)); embed.WithFooter(Bot.Internal.Utilities.GetFormattedLocaleMsg("CommandFooter", Context.User.Username)); config.WelcomeChannel = chnl.Id; GuildConfig.SaveGuildConfig(); await SendMessage(embed); }
public async Task Leveling(bool arg) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); var embed = new EmbedBuilder(); embed.WithFooter(Bot.Utilities.GetFormattedLocaleMsg("CommandFooter", Context.User.Username)); embed.WithColor(new Color(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3)); embed.WithDescription(arg ? "Enabled leveling for this server." : "Disabled leveling for this server."); config.Leveling = arg; GuildConfig.SaveGuildConfig(); await SendMessage(embed); }
internal static async Task HandleMessages(SocketMessage s) { var msg = s as SocketUserMessage; var context = new SocketCommandContext(_client, msg); if (msg == null) { Console.WriteLine($"{s} not cared for as it's null (for whatever reason)"); return; } //Console.WriteLine($"Var msg: {msg}"); //Console.WriteLine($"Var s: {s}"); //Console.WriteLine($"Var context: {context}"); if (context.Guild == null) { var user = await context.User.GetOrCreateDMChannelAsync(); await user.SendMessageAsync("Commands are not available in DMs."); } var config = GuildConfig.GetGuildConfig(context.Guild.Id) ?? GuildConfig.CreateGuildConfig(context.Guild.Id); config.GuildOwnerId = context.Guild.Owner.Id; GuildConfig.SaveGuildConfig(); if (config.Leveling) { await Leveling.UserSentMessage((SocketGuildUser)context.User, (SocketTextChannel)context.Channel); } if (context.Guild.Id == 385902350432206849) { if (msg.Content.Contains("🎷") || msg.Content.Contains("🎺")) { if (msg.Author.Id == 360493978371751937) { await msg.DeleteAsync(); var msgObj = await context.Channel.SendMessageAsync(context.User.Mention + " no"); Thread.Sleep(5000); await msgObj.DeleteAsync(); } } } }
public async Task SetIntIntoConfig(int arg1, int arg2, int arg3) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); config.WelcomeColour1 = arg1; config.WelcomeColour2 = arg2; config.WelcomeColour3 = arg3; GuildConfig.SaveGuildConfig(); var embed = new EmbedBuilder(); embed.WithColor(new Color(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3)); embed.WithDescription(Bot.Internal.Utilities.GetFormattedLocaleMsg("WelcomeColourText", arg1, arg2, arg3)); embed.WithFooter(Bot.Internal.Utilities.GetFormattedLocaleMsg("CommandFooter", Context.User.Username)); await SendMessage(embed); }
public async Task SetBoolIntoConfig(bool setting) { var config = GuildConfig.GetGuildConfig(Context.Guild.Id) ?? GuildConfig.CreateGuildConfig(Context.Guild.Id); config.Antilink = setting; GuildConfig.SaveGuildConfig(); var embed = new EmbedBuilder(); embed.WithFooter(Bot.Utilities.GetFormattedLocaleMsg("CommandFooter", Context.User.Username)); embed.WithColor(new Color(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3)); if (setting) { embed.WithDescription("Enabled Antilink for this server."); } if (setting == false) { embed.WithDescription("Disabled Antilink for this server."); } await ReplyAsync("", false, embed); }
public static async Task SupportSystem(SocketMessage s) { var msg = s as SocketUserMessage; if (msg == null) { return; } var context = new SocketCommandContext(new DiscordSocketClient(), msg); if (context.User.IsBot) { return; } var user = context.User as SocketGuildUser; var config = GuildConfig.GetGuildConfig(context.Guild.Id) ?? GuildConfig.CreateGuildConfig(context.Guild.Id); config.GuildOwnerId = context.Guild.OwnerId; var adminRole = context.Guild.Roles.FirstOrDefault(x => x.Id == config.AdminRole); if (msg.Content == "SetupSupport" && user.Roles.Contains(adminRole)) { var embed = new EmbedBuilder(); embed.WithColor(Config.bot.DefaultEmbedColour); embed.WithDescription(Utilities.GetLocaleMsg("SupportEmbedText")); embed.WithAuthor(context.Guild.Owner); await context.Channel.SendMessageAsync("", false, embed); config.SupportChannelId = context.Channel.Id; config.SupportChannelName = context.Channel.Name; config.CanCloseOwnTicket = true; GuildConfig.SaveGuildConfig(); } if (msg.Content != "SetupSupport") { var supportConfig = GuildConfig.GetGuildConfig(context.Guild.Id); var supportStartChannel = context.Guild.Channels.FirstOrDefault(c => c.Name == supportConfig.SupportChannelName); if (msg.Channel == supportStartChannel) { var supportChannelExists = context.Guild.Channels.FirstOrDefault(c => c.Name == $"{supportConfig.SupportChannelName}-{context.User.Id}"); var role = context.Guild.Roles.FirstOrDefault(r => r.Name == supportConfig.SupportRole); if (supportChannelExists == null) { await msg.DeleteAsync(); var chnl = await context.Guild.CreateTextChannelAsync( $"{supportConfig.SupportChannelName}-{context.User.Id}"); await chnl.AddPermissionOverwriteAsync(context.User, new OverwritePermissions(readMessages : PermValue.Allow, sendMessages : PermValue.Allow, addReactions : PermValue.Allow, sendTTSMessages : PermValue.Deny)); await chnl.AddPermissionOverwriteAsync(context.Guild.EveryoneRole, new OverwritePermissions(readMessages : PermValue.Deny, sendMessages : PermValue.Deny)); if (role != null) { await chnl.AddPermissionOverwriteAsync(role, OverwritePermissions.AllowAll(chnl)); } await chnl.ModifyAsync(x => { x.Position = supportStartChannel.Position - 1; x.Topic = $"Support ticket created by <@{msg.Author.Id}> at {DateTime.UtcNow} (UTC)"; }); var embed = new EmbedBuilder() .WithAuthor(msg.Author) .WithThumbnailUrl(context.User.GetAvatarUrl()) .WithTitle("What do you need help with?") .WithDescription( $"```{msg.Content}```\n\nIf you're done with the ticket, type `{config.CommandPrefix}close`, or react to the message with ☑.") .WithColor(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3) .WithFooter($"Time Created: {DateTime.Now}"); var message = await chnl.SendMessageAsync( $"You can close this ticket if you have the role set for moderating tickets: `{supportConfig.SupportRole}`", false, embed); await message.PinAsync(); await message.AddReactionAsync(new Emoji("☑")); } else { var channel = context.Guild.GetTextChannel(supportChannelExists.Id); await channel.SendMessageAsync( $"{context.User.Mention}, please send your message here rather than the primary support channel. Text: ```{msg.Content}``` If you cannot type in here, please tell an admin."); await msg.DeleteAsync(); } } } }
private async Task HandleCommandAsync(SocketMessage s) { var msg = s as SocketUserMessage; var context = new SocketCommandContext(_client, msg); await EventUtils.AssholeChecks(s); await EventUtils.HandleMessages(s); await Blacklist.CheckMessageForBlacklistedTerms(s); await Support.SupportSystem(s); if (msg == null) { Console.WriteLine($"{s} not cared for as it's null (for whatever reason)"); return; } if (context.User.IsBot) { return; } var config = GuildConfig.GetGuildConfig(context.Guild.Id) ?? GuildConfig.CreateGuildConfig(context.Guild.Id); var prefix = config.CommandPrefix ?? Config.bot.Prefix; if (config.EmbedColour1 == 0 && config.EmbedColour2 == 0 && config.EmbedColour3 == 0) { config.EmbedColour1 = 112; config.EmbedColour2 = 0; config.EmbedColour3 = 251; GuildConfig.SaveGuildConfig(); } var argPos = 0; foreach (var command in config.CustomCommands) { if (msg.HasStringPrefix($"{config.CommandPrefix}{command.Key}", ref argPos)) { await context.Channel.SendMessageAsync(command.Value); break; } } if (msg.HasStringPrefix(prefix, ref argPos) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos)) { var result = await _service.ExecuteAsync(context, argPos); //Console.WriteLine($"Command -{msg.Content}- executed"); if (result.IsSuccess == false && result.ErrorReason != "Unknown command.") { string reason; switch (result.ErrorReason) { case "The server responded with error 403: Forbidden": reason = "I'm not allowed to do that. Either I don't have permission or the requested user is higher than me in the role heirarchy."; break; case "Sequence contains no elements": try { reason = $"{msg.MentionedUsers.FirstOrDefault().Mention} doesn't have any."; } catch (NullReferenceException) { reason = "List has no elements."; } break; case "Failed to parse Boolean": reason = "You can only input `true` or `false` for this command."; break; default: reason = result.ErrorReason; break; } var embed = new EmbedBuilder(); if (msg.HasMentionPrefix(_client.CurrentUser, ref argPos)) { var nm = msg.Content.Replace($"<@{_client.CurrentUser.Id}> ", config.CommandPrefix); embed.AddField("Error in command:", nm); embed.AddField("Error reason:", reason); embed.AddField("Weird error?", "[Report it in the SIVA-dev server](https://discord.gg/prR9Yjq)"); embed.WithAuthor(context.User); embed.WithColor(Config.bot.ErrorEmbedColour); await context.Channel.SendMessageAsync("", false, embed); } else { var nm = msg.Content; embed.AddField("Error in command:", nm); embed.AddField("Error reason:", reason); embed.AddField("Weird error?", "[Report it in the SIVA-dev server](https://discord.gg/prR9Yjq)"); embed.WithAuthor(context.User); embed.WithColor(Config.bot.ErrorEmbedColour); await context.Channel.SendMessageAsync("", false, embed); } } if (result.ErrorReason == "Unknown command.") { return; } if (Config.bot.LogAllCommands) { Console.WriteLine($"--| -Command from user: {context.User.Username}#{context.User.Discriminator}"); Console.WriteLine($"--| -Command Issued: {msg.Content}"); Console.WriteLine($"--| -In Guild: {context.Guild.Name}"); Console.WriteLine($"--| -In Channel: #{context.Channel.Name}"); Console.WriteLine($"--| -Time Issued: {DateTime.Now}"); Console.WriteLine(result.IsSuccess ? $"--| -Executed: {result.IsSuccess}" : $"--| -Executed: {result.IsSuccess} | Reason: {result.ErrorReason}"); Console.WriteLine("-------------------------------------------------"); } try { File.AppendAllText("Commands.log", $"--| -Command from user: {context.User.Username}#{context.User.Discriminator} ({context.User.Id})\n"); File.AppendAllText("Commands.log", $"--| -Command Issued: {msg.Content} ({msg.Id})\n"); File.AppendAllText("Commands.log", $"--| -In Guild: {context.Guild.Name} ({context.Guild.Id})\n"); File.AppendAllText("Commands.log", $"--| -In Channel: #{context.Channel.Name} ({context.Channel.Id})\n"); File.AppendAllText("Commands.log", $"--| -Time Issued: {DateTime.Now}\n"); File.AppendAllText("Commands.log", result.IsSuccess ? $"--| -Executed: {result.IsSuccess}\n" : $"--| -Executed: {result.IsSuccess} | Reason: {result.ErrorReason}\n"); File.AppendAllText("Commands.log", "-------------------------------------------------\n"); } catch (FileNotFoundException) { Console.WriteLine("The Commands.log file wasn't found, creating it now."); File.WriteAllText("Commands.log", ""); } if (config.DeleteMessageOnCommand) { await context.Message.DeleteAsync(); } } else { if (msg.Content.Contains($"<@{_client.CurrentUser.Id}>")) { await Helpers.SendMessage(context, null, "<:whO_PENG:437088256291504130>"); } } }
public static async Task AssholeChecks(SocketMessage s) { var msg = s as SocketUserMessage; var context = new SocketCommandContext(_client, msg); if (context.User.IsBot) { return; } if (msg == null) { return; } var config = GuildConfig.GetGuildConfig(context.Guild.Id); try //attempt something { if (config.Antilink == false) { //if antilink is turned off then do nothing. } else //if it isnt then do the following { if (msg.Author.Id == config.GuildOwnerId) //if the message is from the guild owner { //don't do anything } else //if the message isnt from the guild owner, do the following { if ((msg.Content.Contains("https://discord.gg") || msg.Content.Contains("https://discord.io")) && !config.AntilinkIgnoredChannels.Contains(context.Channel.Id)) //if the message contains https://discord.gg or io (it's an invite link), then delete it { await msg.DeleteAsync(); var embed = new EmbedBuilder(); embed.WithDescription($"{context.User.Mention}, no invite links."); embed.WithColor(Config.bot.DefaultEmbedColour); var mssg = await context.Channel.SendMessageAsync("", false, embed); Thread.Sleep(10000); await mssg.DeleteAsync(); } } } } catch (NullReferenceException) // if the config variable returns an invalid value then create the guild config { GuildConfig.CreateGuildConfig(context.Guild.Id); } if (config.MassPengChecks) { if (msg.Content.Contains("@everyone") || msg.Content.Contains("@here")) { if (msg.Author != context.Guild.Owner) { await msg.DeleteAsync(); var msgg = await context.Channel.SendMessageAsync($"{msg.Author.Mention}, try not to mass ping."); Thread.Sleep(4000); await msgg.DeleteAsync(); } } } }