public static async Task WelcomeMessage(SocketGuildUser user) { var id = user.Guild.Id; var wevent = GuildConfig.Load(id).WelcomeEvent; if (!wevent) { return; } var wchan = GuildConfig.Load(id).WelcomeChannel; var wmessage = GuildConfig.Load(id).WelcomeMessage; var embed = new EmbedBuilder(); if (wchan != 0) { var channel = user.Guild.GetTextChannel(wchan); embed.AddField($"Welcome {user.Username}", wmessage); embed.WithColor(Color.Blue); await channel.SendMessageAsync($"{user.Mention}", false, embed.Build()); } else { embed.AddField($"Welcome {user.Username}", wmessage); embed.WithColor(Color.Blue); await user.Guild.DefaultChannel.SendMessageAsync($"{user.Mention}", false, embed.Build()); } }
public async Task ChannelUpdatedEvent(SocketChannel s1, SocketChannel s2) { var sChannel1 = s1 as SocketGuildChannel; var sChannel2 = s2 as SocketGuildChannel; if (sChannel1 != null) { var guild = sChannel1.Guild; var gChannel = sChannel1; if (GuildConfig.Load(guild.Id).EventLogging) { if (sChannel2 != null && sChannel1.Position != sChannel2.Position) { return; } var embed = new EmbedBuilder(); embed.AddField("Channel Updated", $"{gChannel.Name}"); embed.WithFooter(x => { x.WithText($"{DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)} UTC TIME"); }); embed.Color = Color.Blue; if (GuildConfig.Load(guild.Id).EventChannel != 0) { var channel = guild.GetChannel(GuildConfig.Load(guild.Id).EventChannel); await((ITextChannel)channel).SendMessageAsync("", false, embed.Build()); } } } }
public async Task GoodbyeMessage(SocketGuildUser user) { var id = user.Guild.Id; var gevent = GuildConfig.Load(id).GoodbyeEvent; if (!gevent) { return; } var gchan = GuildConfig.Load(id).GoodByeChannel; var gmessage = GuildConfig.Load(id).GoodbyeMessage; if (gchan != 0) { var channel = user.Guild.GetTextChannel(gchan); //await channel.SendMessageAsync($"{user.Mention}: {gmessage}"); var embed = new EmbedBuilder(); embed.AddField($"Goodbye {user.Username}", $"{gmessage}"); //var channel = user.Guild.GetTextChannel(gchan); await channel.SendMessageAsync($"", false, embed.Build()); } else { var embed = new EmbedBuilder(); embed.AddField($"Goodbye {user.Username}", $"{gmessage}"); //await channel.SendMessageAsync($"", false, embed.Build()); await user.Guild.DefaultChannel.SendMessageAsync($"", false, embed.Build()); } }
public async Task MessageDeletedEvent(Cacheable <IMessage, ulong> message, ISocketMessageChannel channel) { var guild = ((SocketGuildChannel)channel).Guild; if (GuildConfig.Load(guild.Id).EventLogging) { if (_delay > DateTime.UtcNow) { return; } _delay = DateTime.UtcNow.AddSeconds(2); var embed = new EmbedBuilder(); try { embed.AddField("Message Deleted", $"Message: {message.Value.Content}\n" + $"Author: {message.Value.Author}\n" + $"Channel: {channel.Name}"); } catch { embed.AddField("Message Deleted", "Message was unable to be retrieved\n" + $"Channel: {channel.Name}"); } embed.WithFooter(x => { x.WithText($"{DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)} UTC TIME"); }); embed.Color = Color.Green; var cchannel = guild.GetChannel(GuildConfig.Load(guild.Id).EventChannel); await((ITextChannel)cchannel).SendMessageAsync("", false, embed.Build()); } }
public async Task Mute(IGuildUser user) { // 1. Check the user isnt an admin or moderator // 2. Try to get the muted role // 3. If the muted role is not setup, unavailable or does not exist, return. // 4. Try to mute the user. if (user.RoleIds.Contains(GuildConfig.Load(Context.Guild.Id).ModeratorRoleId) || user.GuildPermissions.Administrator) { await ReplyAsync("ERROR: User is a moderator or administrator"); return; } IRole mutedrole; try { var mrole = GuildConfig.Load(Context.Guild.Id).MutedRole; if (mrole == 0) { await ReplyAsync("The servers muted role is not setup"); return; } mutedrole = Context.Guild.GetRole(mrole); } catch { await ReplyAsync("Muted Role has been deleted or could not be found. ERROR"); return; } if (mutedrole == null) { await ReplyAsync("Muted Role has been deleted or could not be found. ERROR"); return; } try { await user.AddRoleAsync(mutedrole); await ReplyAsync($"SUCCESS. The user has been muted and added to the muted role: {mutedrole.Mention}"); } catch { await ReplyAsync("Use role unable to be modified. ERROR"); } }
public async Task Unmute(IGuildUser user) { var muteId = GuildConfig.Load(Context.Guild.Id).MutedRole; var muterole = Context.Guild.GetRole(muteId); if (user.RoleIds.Contains(muteId)) { await user.RemoveRoleAsync(muterole); await ReplyAsync("SUCCESS! User unmuted."); return; } await ReplyAsync("User was not muted to begin with."); }
private void LoadConfigs() { try { BotConfig = BotConfig.Load(); GuildConfig = GuildConfig.Load(); TranslationConfig = TranslationConfig.Load(); AliasConfig = AliasConfig.Load(); } catch (Exception e) { _logger.Error($"Error loading config:\n{e}\n\nPress any key to continue"); Console.ReadKey(); } }
public async Task Tagdel(string tagname) { var file = Path.Combine(AppContext.BaseDirectory, $"setup/server/{Context.Guild.Id}.json"); var jsononb = JsonConvert.DeserializeObject <GuildConfig>(File.ReadAllText(file)); try { var dict = GuildConfig.Load(Context.Guild.Id).Dict; foreach (var tagging in dict) { if (tagging.Tagname.ToLower() == tagname.ToLower()) { if (((SocketGuildUser)Context.User).GuildPermissions.Administrator) { dict.Remove(tagging); await ReplyAsync("Tag Deleted using Admin Permissions"); jsononb.Dict = dict; var output = JsonConvert.SerializeObject(jsononb, Formatting.Indented); File.WriteAllText(file, output); return; } if (tagging.Creator == Context.User.Id) { dict.Remove(tagging); await ReplyAsync("Tag Deleted By Owner"); jsononb.Dict = dict; var output = JsonConvert.SerializeObject(jsononb, Formatting.Indented); File.WriteAllText(file, output); return; } await ReplyAsync("You do not own this tag"); return; } } await ReplyAsync($"No Tags found with the name: {tagname}"); } catch { await ReplyAsync("No Tags To Delete"); } }
public async Task UserLeftEvent(SocketGuildUser user) { if (GuildConfig.Load(user.Guild.Id).EventLogging) { var embed = new EmbedBuilder(); embed.AddField("User Left", $"Username: {user.Username}"); embed.WithFooter(x => { x.WithText($"{DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)} UTC TIME"); }); embed.Color = Color.Red; if (GuildConfig.Load(user.Guild.Id).EventChannel != 0) { var channel = user.Guild.GetChannel(GuildConfig.Load(user.Guild.Id).EventChannel); await((ITextChannel)channel).SendMessageAsync("", false, embed.Build()); } } }
public override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) { var id = context.Guild.Id; var role = GuildConfig.Load(id).DjRoleId; if (role == 0) { return(Task.FromResult(PreconditionResult.FromSuccess())); } if (((IGuildUser)context.User).RoleIds.Contains(role)) { return(Task.FromResult(PreconditionResult.FromSuccess())); } return(Task.FromResult(PreconditionResult.FromError("User is Not DJ"))); }
public async Task Tagadd(string tagname, [Remainder] string tagmessage) { var tg = new Tagging { Tagname = tagname, Content = tagmessage, Creator = Context.User.Id }; var file = Path.Combine(AppContext.BaseDirectory, $"setup/server/{Context.Guild.Id}.json"); var jsononb = JsonConvert.DeserializeObject <GuildConfig>(File.ReadAllText(file)); try { var d = GuildConfig.Load(Context.Guild.Id).Dict; foreach (var tagging in d) { if (tagging.Tagname == tagname) { await ReplyAsync( $"**{tagname}** is already a tag in this server, if you want to edit it, please delete it first, then add the new tag"); return; } } d.Add(tg); jsononb.Dict = d; var output = JsonConvert.SerializeObject(jsononb, Formatting.Indented); File.WriteAllText(file, output); await ReplyAsync("Tags List Updated"); } catch { var d = new List <Tagging> { tg }; jsononb.Dict = d; var output = JsonConvert.SerializeObject(jsononb, Formatting.Indented); File.WriteAllText(file, output); } }
public async Task ChannelCreatedEvent(SocketChannel sChannel) { var guild = ((SocketGuildChannel)sChannel).Guild; var gChannel = (SocketGuildChannel)sChannel; if (GuildConfig.Load(guild.Id).EventLogging) { var embed = new EmbedBuilder(); embed.AddField("Channel Created", $"{gChannel.Name}"); embed.WithFooter(x => { x.WithText($"{DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)} UTC TIME"); }); embed.Color = Color.Green; if (GuildConfig.Load(guild.Id).EventChannel != 0) { var channel = guild.GetChannel(GuildConfig.Load(guild.Id).EventChannel); await((ITextChannel)channel).SendMessageAsync("", false, embed.Build()); } } }
public override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) { var id = context.Guild.Id; var role = GuildConfig.Load(id).ModeratorRoleId; if (role == 0) { if (((IGuildUser)context.User).GuildPermissions.Administrator) { return(Task.FromResult(PreconditionResult.FromSuccess())); } } else { if (((IGuildUser)context.User).RoleIds.Contains(role)) { return(Task.FromResult(PreconditionResult.FromSuccess())); } } return(Task.FromResult(PreconditionResult.FromError("User is Not A Moderator or an Admin!"))); }
public async Task MessageUpdatedEvent(Cacheable <IMessage, ulong> messageOld, SocketMessage messageNew, ISocketMessageChannel cchannel) { var guild = ((SocketGuildChannel)cchannel).Guild; if (messageNew.Author.IsBot) { return; } if (string.Equals(messageOld.Value.Content, messageNew.Content, StringComparison.CurrentCultureIgnoreCase)) { return; } if (messageOld.Value.Embeds.Count == 0 && messageNew.Embeds.Count == 1) { return; } if (GuildConfig.Load(guild.Id).EventLogging) { var embed = new EmbedBuilder(); embed.AddField("Message Updated", $"Author: {messageNew.Author.Username}\n" + $"Old Message: {messageOld.Value.Content}\n" + $"New Message: {messageNew.Content}"); embed.WithFooter(x => { x.WithText($"{DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)} UTC TIME"); }); embed.Color = Color.Green; if (GuildConfig.Load(guild.Id).EventChannel != 0) { var channel = guild.GetChannel(GuildConfig.Load(guild.Id).EventChannel); await((ITextChannel)channel).SendMessageAsync("", false, embed.Build()); } } }
public async Task ConfigInfo() { var embed = new EmbedBuilder(); var l = GuildConfig.Load(Context.Guild.Id); string djstring; string guildstring; //string errorLogString; string subrolelist; string rss; string tags; string welcome; string goodbye; string nomention; string noinvite; string eventlogging; string admincommands; string blacklist; string modRole; try { subrolelist = ""; foreach (var role in l.RoleList) { subrolelist += $"{Context.Guild.GetRole(role).Name}\n"; } } catch { subrolelist = "There are no joinable roles"; } try { if (l.ModeratorRoleId == 0) { modRole = "N/A"; } else { var mrole = Context.Guild.GetRole(l.ModeratorRoleId); modRole = mrole.Name; } } catch { modRole = $"@deleted-role <{l.ModeratorRoleId}>"; } try { djstring = Context.Guild.GetRole(l.DjRoleId).Name; } catch { djstring = "There is no DJ role configured"; } try { guildstring = $"{l.GuildName}, {l.GuildId}"; } catch { guildstring = $"{Context.Guild.Name}, {Context.Guild.Id}"; } /*try * { * errorLogString = l.ErrorLog ? "Status: On" : "Status: Off"; * } * catch * { * errorLogString = "Status: Off"; * }*/ try { rss = $"{l.Rss}, {Context.Guild.GetChannel(l.RssChannel).Name}"; } catch { rss = "Status: Disabled"; } try { var dict = GuildConfig.Load(Context.Guild.Id).Dict; var list = ""; foreach (var tagging in dict) { list += $"{tagging.Tagname}, "; } tags = list.Substring(0, list.Length - 2); } catch { tags = "there are none yet...."; } try { var status = l.WelcomeEvent ? "On" : "Off"; welcome = $"Status: {status}\n" + $"Channel: {Context.Guild.GetChannel(l.WelcomeChannel).Name}\n" + $"Message: {l.WelcomeMessage}"; } catch { welcome = "Status: Disabled"; } try { var status = l.GoodbyeEvent ? "On" : "Off"; goodbye = $"Status: {status}\n" + $"Channel: {Context.Guild.GetChannel(l.GoodByeChannel).Name}\n" + $"Message: {l.GoodbyeMessage}"; } catch { goodbye = "Status: Disabled"; } try { nomention = l.MentionAll ? "Status: On" : "Status: Off"; } catch { nomention = "Status: Off"; } try { noinvite = l.Invite ? "Status: On" : "Status: Off"; } catch { noinvite = "Status: Off"; } try { if (l.EventLogging) { eventlogging = $"Status: On\n" + $"Channel: {Context.Guild.GetChannel(l.EventChannel).Name}"; } else { eventlogging = "Status: Off"; } } catch { eventlogging = "Disabled"; } try { admincommands = $"Warnings: {l.Warnings.Count}\n" + $"Kicks: {l.Kicking.Count}\n" + $"Bans: {l.Banning.Count}"; } catch { admincommands = "Warnings: 0\n" + "Kicks: 0\n" + "Bans: 0"; } try { blacklist = $"{l.Blacklist.Count}"; } catch { blacklist = $"0"; } embed.AddField("DJ Role", $"Role: {djstring}"); embed.AddField("Guild Name & ID", guildstring); //embed.AddField("Error logging", $"Status: {errorLogString}"); embed.AddField("SubRoles", $"Role: {subrolelist}"); embed.AddField("RSS URL/Channel", $"{rss}"); embed.AddField("Tags", $"{tags}"); embed.AddField("Welcome", $"{welcome}"); embed.AddField("Goodbye", $"{goodbye}"); embed.AddField("NoMention", $"{nomention}"); embed.AddField("NoInvite", $"Status: {noinvite}"); embed.AddField("EventLogging", eventlogging); embed.AddField("Admin Uses", admincommands); embed.AddField("Blacklisted Word Count", blacklist); embed.AddField("Moderator Role", modRole); await ReplyAsync("", false, embed.Build()); }
public async Task InitialiseWelcome() { await ReplyAsync("```\n" + "Reply with the command you would like to perform\n" + "[1] Set the welcome message\n" + "[2] Set the current channel for welcome events\n" + "[3] Enable the welcome event\n" + "[4] Disable the welcome event\n" + "[5] View Welcome Info" + "" + "```"); var next = await NextMessageAsync(); if (next.Content == "1") { await ReplyAsync( "Please reply with the welcome message you want to be sent when a user joins the server ie. `Welcome to Our Server!!`"); var next2 = await NextMessageAsync(); GuildConfig.SetWMessage(Context.Guild, next2.Content); GuildConfig.SetWChannel(Context.Guild, Context.Channel.Id); await ReplyAsync("The Welcome Message for this server has been set to:\n" + $"**{next2.Content}**\n" + $"In the channel **{Context.Channel.Name}**"); } else if (next.Content == "2") { GuildConfig.SetWChannel(Context.Guild, Context.Channel.Id); await ReplyAsync($"Welcome Events will be sent in the channel: **{Context.Channel.Name}**"); } else if (next.Content == "3") { GuildConfig.SetWelcomeStatus(Context.Guild, true); await ReplyAsync("Welcome Messageing for this server has been set to: true"); } else if (next.Content == "4") { GuildConfig.SetWelcomeStatus(Context.Guild, false); await ReplyAsync("Welcome Messageing for this server has been set to: false"); } else if (next.Content == "5") { var l = GuildConfig.Load(Context.Guild.Id); var embed = new EmbedBuilder(); try { embed.AddField("Message", l.WelcomeMessage); embed.AddField("Channel", Context.Guild.GetChannel(l.WelcomeChannel).Name); embed.AddField("Status", l.WelcomeEvent ? "On" : "Off"); await ReplyAsync("", false, embed.Build()); } catch { await ReplyAsync( "Error, this guilds welcome config is not fully set up yet, please consider using options 1 thru 4 first"); } } else { await ReplyAsync("ERROR: you did not supply an option. type only `1` etc."); } }
public async Task DoCommand(SocketMessage parameterMessage) { Load.Messages++; if (!(parameterMessage is SocketUserMessage message)) { return; } var argPos = 0; var context = new ShardedCommandContext(_client, message); //new CommandContext(_client, message); if (context.User.IsBot) { return; } if (message.Content.Contains("discord.gg")) { try { if (context.Channel is IGuildChannel) { if (GuildConfig.Load(context.Guild.Id).Invite&& !((SocketGuildUser)context.User).GuildPermissions.Administrator) { if (!((IGuildUser)context.User).RoleIds .Intersect(GuildConfig.Load(context.Guild.Id).InviteExcempt).Any()) { await message.DeleteAsync(); await context.Channel.SendMessageAsync( $"{context.User.Mention} - Pls Daddy, no sending invite links... the admins might get angry"); //if // 1. The server Has Invite Deletions turned on // 2. The user is not an admin // 3. The user does not have one of the invite excempt roles } } } } catch { // } } if (message.Content.Contains("@everyone") || message.Content.Contains("@here")) { try { if (context.Channel is IGuildChannel) { if (GuildConfig.Load(context.Guild.Id).MentionAll&& !((SocketGuildUser)context.User).GuildPermissions.Administrator) { if (!((IGuildUser)context.User).RoleIds .Intersect(GuildConfig.Load(context.Guild.Id).InviteExcempt).Any()) { await message.DeleteAsync(); var rnd = new Random(); var res = rnd.Next(0, FunStr.Everyone.Length); var emb = new EmbedBuilder { Title = $"{context.User} - the admins might get angry", ImageUrl = FunStr.Everyone[res] }; await context.Channel.SendMessageAsync("", false, emb.Build()); //if // 1. The server Has Mention Deletions turned on // 2. The user is not an admin // 3. The user does not have one of the mention excempt roles } } } } catch { // } } try { if (GuildConfig.Load(context.Guild.Id).Blacklist .Any(b => context.Message.Content.ToLower().Contains(b.ToLower())) && !((IGuildUser)context.User).GuildPermissions.Administrator) { await message.DeleteAsync(); var blmessage = ""; try { blmessage = GuildConfig.Load(context.Guild.Id).BlacklistMessage; } catch { // } if (blmessage != "") { var r = await context.Channel.SendMessageAsync(blmessage); await Task.Delay(5000); await r.DeleteAsync(); } } } catch { // } if (!(message.HasMentionPrefix(_client.CurrentUser, ref argPos) || message.HasStringPrefix(Load.Pre, ref argPos) || message.HasStringPrefix(GuildConfig.Load(context.Guild.Id).Prefix, ref argPos))) { return; } if (message.HasMentionPrefix(_client.CurrentUser, ref argPos)) { var newmessage = Regex.Replace(context.Message.Content, @"^\!?<@[0-9]+>\s*", "", RegexOptions.Multiline); var response = _apiAi.TextRequest(newmessage); if (response.Result.Fulfillment.Speech != "") { await context.Channel.SendMessageAsync(response.Result.Fulfillment.Speech); } return; } var result = await _commands.ExecuteAsync(context, argPos, Provider); var commandsuccess = result.IsSuccess; string server; if (context.Channel is IPrivateChannel) { server = "Direct Message "; //because direct messages have no guild name define it as Direct Message } else { server = context.Guild.Name; } if (!commandsuccess) { try { if (!(result.ErrorReason == "Unknown command." || result.ErrorReason == "The input text has too many parameters." || result.ErrorReason == "The input text has too few parameters." || result.ErrorReason == "Timeout" || result.ErrorReason == "This command may only be invoked in an NSFW channel." || result.ErrorReason == "Command can only be run by the owner of the bot" || result.ErrorReason == "This command is locked to NSFW Channels. Pervert.")) { var s = Homeserver.Load().Error; var c = await(context.Client as IDiscordClient).GetChannelAsync(s); var embed = new EmbedBuilder(); embed.AddField("ERROR", context.Message); embed.AddField("Reason", result.ErrorReason); embed.WithFooter(x => { x.Text = $"{context.Message.CreatedAt} || {context.Guild.Name}"; }); embed.Color = Color.Red; await((ITextChannel)c).SendMessageAsync("", false, embed.Build()); } } catch { // } var errmessage = await context.Channel.SendMessageAsync( $"**COMMAND: **{context.Message} \n**ERROR: **{result.ErrorReason}"); //if in server error responses are enabled reply on error await Task.Delay(5000); await errmessage.DeleteAsync(); await context.Message.DeleteAsync(); await ColourLog.In3Error($"{context.Message}", 'S', $"{context.Guild.Name}", 'E', $"{result.ErrorReason}"); // log errors as arrors } else { await ColourLog.In3( $"{context.Message}", 'S', $"{server}", 'U', $"{context.User}", System.Drawing.Color.Teal); //if there is no error log normally Load.Commands++; } }
public async Task HelpAsync([Remainder] string modulearg = null) { string isserver; if (Context.Channel is IPrivateChannel) { isserver = Load.Pre; } else { try { isserver = GuildConfig.Load(Context.Guild.Id).Prefix; } catch { isserver = Load.Pre; } } var embed = new EmbedBuilder { Color = new Color(114, 137, 218), Title = $"PassiveBOT | Commands | Prefix: {isserver}" }; if (modulearg == null) //ShortHelp { foreach (var module in _service.Modules) { var list = module.Commands.Select(command => command.Name).ToList(); if (module.Commands.Count > 0) { embed.AddField(x => { x.Name = module.Name; x.Value = string.Join(", ", list); }); } } embed.AddField("\n\n**NOTE**", $"You can also see modules in more detail using `{isserver}help <modulename>`\n" + $"Also Please consider supporting this project on patreon: <https://www.patreon.com/passivebot>"); } else { foreach (var module in _service.Modules) { if (module.Name.ToLower() == modulearg.ToLower()) { var list = new List <string>(); foreach (var command in module.Commands) { list.Add( $"`{isserver}{command.Summary}` - {command.Remarks}"); if (string.Join("\n", list).Length > 800) { embed.AddField(module.Name, string.Join("\n", list)); list = new List <string>(); } } embed.AddField(module.Name, string.Join("\n", list)); } } if (embed.Fields.Count == 0) { embed.AddField("Error", $"{modulearg} is not a module"); var list = _service.Modules.Select(module => module.Name).ToList(); embed.AddField("Modules", string.Join("\n", list)); } } await ReplyAsync("", false, embed.Build()); }
public async Task Tag(string tagname = null) { if (tagname == null) { try { var dict = GuildConfig.Load(Context.Guild.Id).Dict; var list = ""; foreach (var tagging in dict) { list += $"{tagging.Tagname}, "; } var res = list.Substring(0, list.Length - 2); await ReplyAsync($"**Tags:** {res}"); } catch { await ReplyAsync("This server has no tags added"); } } else { try { var dict = GuildConfig.Load(Context.Guild.Id).Dict; var embed = new EmbedBuilder(); foreach (var tagging in dict) { if (tagging.Tagname.ToLower() == tagname.ToLower()) { string ownername; try { var own = await Context.Guild.GetUserAsync(tagging.Creator); ownername = own.Username; } catch { ownername = "Owner Left"; } embed.AddField(tagging.Tagname, tagging.Content); embed.WithFooter(x => { x.Text = $"Tag Owner: {ownername} || Command Invokee: {Context.User.Username}"; }); await ReplyAsync("", false, embed.Build()); return; } } await ReplyAsync($"No tag with the name **{tagname}** exists."); } catch { await ReplyAsync("This server has no tags :("); } } }