public async Task BanUser(IGuildUser user, string reason = null) { try { if (reason == null) { await CommandHandeling.ReplyAsync(Context, "Boole! You need to specify reason!"); return; } await user.Guild.AddBanAsync(user, 0, reason); var time = DateTime.Now.ToString(""); var account = UserAccounts.GetAccount((SocketUser) user, Context.Guild.Id); account.Warnings += $"{time} {Context.User}: [ban]" + reason + "|"; UserAccounts.SaveAccounts(Context.Guild.Id); var embed = new EmbedBuilder() .WithColor(Color.DarkRed) .AddField("💥 **ban** used", $"By {Context.User.Mention} in {Context.Channel}\n" + $"**Content:**\n" + $"{user.Mention} - {reason}") .WithThumbnailUrl(Context.User.GetAvatarUrl()) .WithTimestamp(DateTimeOffset.UtcNow); var guild = ServerAccounts.GetServerAccount(Context.Guild); await Context.Guild.GetTextChannel(guild.LogChannelId).SendMessageAsync("", false, embed.Build()); } catch { // await ReplyAsync( // "boo... An error just appear >_< \nTry to use this command properly: **ban [user_ping(or user ID)] [reason_mesasge]**\n" + // "Alias: бан"); } }
public async Task SetBirthdayrole(string role = null) { var guildAccount = ServerAccounts.GetServerAccount(Context.Guild); if (role != null) { var list = Context.Guild.Roles.SingleOrDefault(x => string.Equals(x.Name, role, StringComparison.CurrentCultureIgnoreCase)); if (list != null) { guildAccount.BirthdayRoleId = list.Id; ServerAccounts.SaveServerAccounts(); await CommandHandeling.ReplyAsync(Context, $"Birthday role set! ({list.Name})"); } else { await CommandHandeling.ReplyAsync(Context, "No such role found"); return; } } if (role == null) { var change = await Context.Guild.CreateRoleAsync($"🍰", new GuildPermissions(), Color.Gold, true, RequestOptions.Default); await change.ModifyAsync(p => p.Position = 2); guildAccount.BirthdayRoleId = change.Id; ServerAccounts.SaveServerAccounts(); await CommandHandeling.ReplyAsync(Context, $"We have creatyed and set Birthday role! ({change.Name})"); } }
public async Task SetServerActivivtyLogOff() { var guild = ServerAccounts.GetServerAccount(Context.Guild); guild.LogChannelId = 0; guild.ServerActivityLog = 0; ServerAccounts.SaveServerAccounts(); await CommandHandeling.ReplyAsync(Context, $"Boole."); }
public async Task BuildExistingServer() { var guild = Global.Client.Guilds.ToList(); foreach (var t in guild) { ServerAccounts.GetServerAccount(t); } await CommandHandeling.ReplyAsync(Context, "Севера бобавлены, бууууль!"); }
public async Task SetBirthdayrole(SocketRole role = null) { var guildAccount = _serverAccounts.GetServerAccount(Context.Guild); if (role != null) { guildAccount.BirthdayRoleId = role.Id; } if (role == null) { var change = await Context.Guild.CreateRoleAsync($"🍰", new GuildPermissions(), Color.Gold, true, RequestOptions.Default); await change.ModifyAsync(p => p.Position = 2); guildAccount.BirthdayRoleId = change.Id; await SendMessAsync($"We have creatyed and set Birthday role - **{change.Name}**!"); } }
// [RequireUserPermission(GuildPermission.Administrator)] public async Task WarnUser(IGuildUser user, [Remainder] string message = null) { try { if (message == null) { await CommandHandeling.ReplyAsync(Context, "Boole! You need to specify reason!"); return; } var check = Context.User as IGuildUser; var comander = UserAccounts.GetAccount(Context.User, Context.Guild.Id); if (check != null && (comander.OctoPass >= 100 || comander.IsModerator >= 1 || check.GuildPermissions.ManageRoles || check.GuildPermissions.ManageMessages)) { var time = DateTime.Now.ToString(""); var account = UserAccounts.GetAccount((SocketUser) user, Context.Guild.Id); account.Warnings += $"{time} {Context.User}: [warn]" + message + "|"; UserAccounts.SaveAccounts(Context.Guild.Id); await CommandHandeling.ReplyAsync(Context, user.Mention + " Was Forewarned"); var embed = new EmbedBuilder() .WithColor(Color.DarkRed) .AddField("📉 **WARN** used", $"By {Context.User.Mention} in {Context.Channel}\n" + $"**Content:**\n" + $"{user.Mention} - {message}") .WithThumbnailUrl(Context.User.GetAvatarUrl()) .WithTimestamp(DateTimeOffset.UtcNow); var guild = ServerAccounts.GetServerAccount(Context.Guild); await Context.Guild.GetTextChannel(guild.LogChannelId).SendMessageAsync("", false, embed.Build()); } else { await CommandHandeling.ReplyAsync(Context, "Boole! You do not have a tolerance of this level!"); } } catch { // await ReplyAsync( // "boo... An error just appear >_< \nTry to use this command properly: **warn [user_ping(or user ID)] [reason_mesasge]**\n" + // "Alias: варн, warning, предупреждение"); } }
public async Task UserJoined_ForRoleOnJoin(SocketGuildUser arg) { var guid = _serverAccounts.GetServerAccount(arg.Guild); if (guid.RoleOnJoin == null) { return; } var roleToGive = arg.Guild.Roles .SingleOrDefault(x => x.Name.ToString().ToLower() == $"{guid.RoleOnJoin.ToLower()}"); await arg.AddRoleAsync(roleToGive); }
public async Task LoggingMessEditIgnore(int ignore) { if (ignore < 0 || ignore > 2000) { await CommandHandeling.ReplyAsync(Context, "limit 0-2000"); return; } var guild = ServerAccounts.GetServerAccount(Context.Guild); guild.LoggingMessEditIgnoreChar = ignore; ServerAccounts.SaveServerAccounts(); await CommandHandeling.ReplyAsync(Context, $"Boole? From now on we will ignore {ignore} characters for logging **Message Edit**\n" + "Hint: Space is 1 char, an this: `1` is 3 characters (special formatting characters counts as well)"); }
public async Task AddCustomRoleToBotList(string command, [Remainder] string role) { var guild = ServerAccounts.GetServerAccount(Context.Guild); var check = Context.User as IGuildUser; var comander = UserAccounts.GetAccount(Context.User, Context.Guild.Id); if (check != null && (comander.OctoPass >= 100 || comander.IsModerator >= 1 || check.GuildPermissions.ManageRoles || check.GuildPermissions.ManageMessages)) { var serverRolesList = Context.Guild.Roles.ToList(); var ifSuccsess = false; for (var i = 0; i < serverRolesList.Count; i++) { if (!string.Equals(serverRolesList[i].Name, role, StringComparison.CurrentCultureIgnoreCase) || ifSuccsess) { continue; } var i1 = i; guild.Roles.AddOrUpdate(command, serverRolesList[i].Name, (key, value) => serverRolesList[i1].Name); ServerAccounts.SaveServerAccounts(); ifSuccsess = true; } if (ifSuccsess) { var embed = new EmbedBuilder(); embed.AddField("New Role Command Added To The List:", "Boole!\n" + $"`{guild.Prefix}{command}` will give the user `{role}` Role\n" + ".\n" + "**_____**\n" + "`ar` - see all Role Commands\n" + $"`dr {command}` - remove the command from the list" + "Btw, you can say **role @user role_name** as well."); embed.WithFooter("Tip: Simply edit the previous message instead of writing a new command"); await CommandHandeling.ReplyAsync(Context, embed); } else { await CommandHandeling.ReplyAsync(Context, "Error.\n" + "Example: `add KeyName RoleName` where **KeyName** anything you want(even emoji), and **RoleName** is a role, you want to get by using `*KeyName`\n" + "You can type **RoleName** all lowercase\n\n" + "Saying `*KeyName` you will get **RoleName** role."); } } }
public async Task DeleteCustomRoles(string role) { var guild = ServerAccounts.GetServerAccount(Context.Guild); var embed = new EmbedBuilder(); embed.WithColor(SecureRandomStatic.Random(254), SecureRandomStatic.Random(254), SecureRandomStatic.Random(254)); embed.WithAuthor(Context.User); var test = guild.Roles.TryRemove(role, out role); var text = test ? $"{role} Removed" : "error"; embed.AddField("Delete Custom Role:", $"{text}"); await CommandHandeling.ReplyAsync(Context, embed); }
public async Task SetLanguage(string lang) { if (lang.ToLower() != "en" && lang.ToLower() != "ru") { await CommandHandeling.ReplyAsync(Context, $"boole! only available options for now: `en`(default) and `ru`"); return; } var guild = ServerAccounts.GetServerAccount(Context.Guild); guild.Language = lang.ToLower(); ServerAccounts.SaveServerAccounts(); await CommandHandeling.ReplyAsync(Context, $"boole~ language is now: `{lang.ToLower()}`"); }
public async Task AddCustomRoleToUser([Remainder] string role) { var guild = ServerAccounts.GetServerAccount(Context.Guild); var guildRoleList = guild.Roles.ToArray(); SocketRole roleToAdd = null; if (guildRoleList.Any(x => x.Key == role)) { foreach (var t in guildRoleList) { if (t.Key == role) { roleToAdd = Context.Guild.Roles.SingleOrDefault(x => x.Name.ToString() == t.Value); } else { return; } } } if (!(Context.User is SocketGuildUser guildUser) || roleToAdd == null) { return; } var roleList = guildUser.Roles.ToArray(); if (roleList.Any(t => t.Name == roleToAdd.Name)) { await guildUser.RemoveRoleAsync(roleToAdd); await CommandHandeling.ReplyAsync(Context, $"-{roleToAdd.Name}"); return; } await guildUser.AddRoleAsync(roleToAdd); await CommandHandeling.ReplyAsync(Context, $"+{roleToAdd.Name}"); }
public async Task SetRoleOnJoin(string role = null) { string text; var guild = ServerAccounts.GetServerAccount(Context.Guild); if (role == null) { guild.RoleOnJoin = null; text = $"boole... No one will get role on join from me!"; } else { guild.RoleOnJoin = role; text = $"boole. Everyone will now be getting {role} role on join!"; } ServerAccounts.SaveServerAccounts(); await CommandHandeling.ReplyAsync(Context, text); }
public async Task AllCustomRoles() { var guild = ServerAccounts.GetServerAccount(Context.Guild); var rolesList = guild.Roles.ToList(); var embed = new EmbedBuilder(); embed.WithColor(SecureRandomStatic.Random(254), SecureRandomStatic.Random(254), SecureRandomStatic.Random(254)); embed.WithAuthor(Context.User); var text = ""; foreach (var t in rolesList) { text += $"{t.Key} - {t.Value}\n"; } embed.AddField("All Custom Commands To Get Roles:", $"Format: **KeyName - RoleName**\n" + $"By Saying `{guild.Prefix}KeyName` you will get **RoleName** role.\n" + $"**______**\n\n" + $"{text}\n"); embed.WithFooter("Say **dr KeyName** to delete the Command from the list"); await CommandHandeling.ReplyAsync(Context, embed); }
public async Task SetPrefix([Remainder] string prefix) { try { if (prefix.Length >= 5) { await CommandHandeling.ReplyAsync(Context, $"boole!! Please choose prefix using up to 4 characters"); return; } var guild = ServerAccounts.GetServerAccount(Context.Guild); guild.Prefix = prefix; ServerAccounts.SaveServerAccounts(); await CommandHandeling.ReplyAsync(Context, $"boole is now: `{guild.Prefix}`"); } catch { // } }
public async Task MessageReceived(SocketMessage message) { try { if (message.Author.IsBot || message.Content.Length > 30) { return; } var account = _accounts.GetAccount(message.Author.Id); var server = _global.Client.Guilds.FirstOrDefault(x => x.Channels.Any(b => b.Id == message.Channel.Id)); var guild = _serverAccounts.GetServerAccount(server); var rolesToGiveList = guild.Roles.ToList(); if (rolesToGiveList.Count == 0) { return; } var roleToGive = "2gagwerweghsxbd"; var userCheck = "ju"; if (account.MyPrefix != null) { userCheck = message.Content.Substring(0, account.MyPrefix.Length); } var serverCheck = message.Content.Substring(0, guild.Prefix.Length); if (serverCheck == guild.Prefix) { roleToGive = message.Content.Substring(guild.Prefix.Length, message.Content.Length - guild.Prefix.Length); } if (userCheck == account.MyPrefix) { roleToGive = message.Content.Substring(account.MyPrefix.Length, message.Content.Length - account.MyPrefix.Length); } if (userCheck != account.MyPrefix && serverCheck != guild.Prefix) { return; } if (rolesToGiveList.Any(x => string.Equals(x.Key, roleToGive, StringComparison.CurrentCultureIgnoreCase))) { SocketRole roleToAdd = null; foreach (var t in rolesToGiveList) { if (string.Equals(t.Key, roleToGive, StringComparison.CurrentCultureIgnoreCase)) { if (server != null) { roleToAdd = server.Roles.SingleOrDefault(x => string.Equals(x.Name.ToString(), t.Value, StringComparison.CurrentCultureIgnoreCase)); } } } if (!(message.Author is SocketGuildUser guildUser) || roleToAdd == null) { return; } var roleList = guildUser.Roles.ToArray(); try { if (roleList.Any(t => string.Equals(t.Name, roleToAdd.Name, StringComparison.CurrentCultureIgnoreCase))) { await guildUser.RemoveRoleAsync(roleToAdd); await message.Channel.SendMessageAsync($"-{roleToAdd.Name}"); return; } await guildUser.AddRoleAsync(roleToAdd); await message.Channel.SendMessageAsync($"+{roleToAdd.Name}"); } catch { await message.Channel.SendMessageAsync($"Error. Please make sure, that OctoBot's role is higher than yours"); } } } catch { //ignored } }
//[RequireUserPermission(GuildPermission.Administrator)] public async Task Delete(int number, IGuildUser user = null) { try { if (number > 101 || number < 0) { await CommandHandeling.ReplyAsync(Context, "Limit 100 messages. You may say `clear 5` or `clear 5 @user`" + "if you want to delte a users' messages"); return; } var check = Context.User as IGuildUser; var comander = UserAccounts.GetAccount(Context.User, Context.Guild.Id); if (check != null && (comander.OctoPass >= 100 || comander.IsModerator >= 1 || check.GuildPermissions.ManageMessages)) { if (user == null) { var items = Context.Channel.GetCachedMessages(number+1); if (Context.Channel is ITextChannel channel) await channel.DeleteMessagesAsync(items); } else { var items = Context.Channel.GetCachedMessages(300); List<ulong> messagesToDelte = new List<ulong>(); var count = 0; var messagesList = items.ToList(); for (var i = 0; i < messagesList.Count-1; i++) { if(count == number) continue; if (messagesList[i].Author == user as SocketUser) { messagesToDelte.Add(messagesList[i].Id); count++; } } if(count <= 0) return; if (Context.Channel is ITextChannel channel) await channel.DeleteMessagesAsync(messagesToDelte); } var embed = new EmbedBuilder(); embed.WithColor(Color.DarkRed); embed.AddField($"🛡️**PURGE** {number}", $"Used By {Context.User.Mention} in {Context.Channel}") .WithThumbnailUrl(Context.User.GetAvatarUrl()) .WithTimestamp(DateTimeOffset.UtcNow); var guild = ServerAccounts.GetServerAccount(Context.Guild); await Context.Guild.GetTextChannel(guild.LogChannelId).SendMessageAsync("", false, embed.Build()); } else { await CommandHandeling.ReplyAsync(Context, "Boole! You do not have a tolerance of this level!"); } } catch { // await ReplyAsync( // "boo... An error just appear >_< \nTry to use this command properly: **clear [number]**\n" + // "Alias: purge, clean, убрать"); } }
public async Task BuildExistingServer() { var guild = _global.Client.Guilds.ToList(); foreach (var t in guild) { _serverAccounts.GetServerAccount(t); } await SendMessAsync("Севера бобавлены, бууууль!"); }
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed #pragma warning disable CS1998 // This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. public async Task MessageReceived(SocketMessage message, DiscordShardedClient client) { try { if (message.Author.IsBot) { return; } var context = new ShardedCommandContextCustom(client, message as SocketUserMessage); var account = UserAccounts.GetAccount(context.User, context.Guild.Id); var guild = ServerAccounts.GetServerAccount(context.Guild); var rolesToGiveList = guild.Roles.ToList(); var roleToGive = "2gagwerweghsxbd"; var userCheck = "ju"; if (account.MyPrefix != null) { userCheck = context.Message.Content.Substring(0, account.MyPrefix.Length); } var serverCheck = context.Message.Content.Substring(0, guild.Prefix.Length); if (serverCheck == guild.Prefix) { roleToGive = context.Message.Content.Substring(guild.Prefix.Length, message.Content.Length - guild.Prefix.Length); } if (userCheck == account.MyPrefix) { roleToGive = context.Message.Content.Substring(account.MyPrefix.Length, message.Content.Length - account.MyPrefix.Length); } if (userCheck != account.MyPrefix && serverCheck != guild.Prefix) { return; } if (rolesToGiveList.Any(x => string.Equals(x.Key, roleToGive, StringComparison.CurrentCultureIgnoreCase))) { SocketRole roleToAdd = null; foreach (var t in rolesToGiveList) { if (string.Equals(t.Key, roleToGive, StringComparison.CurrentCultureIgnoreCase)) { roleToAdd = context.Guild.Roles.SingleOrDefault(x => x.Name.ToString().ToLower() == t.Value.ToLower()); } } if (!(context.User is SocketGuildUser guildUser) || roleToAdd == null) { return; } var roleList = guildUser.Roles.ToArray(); if (roleList.Any(t => string.Equals(t.Name, roleToAdd.Name, StringComparison.CurrentCultureIgnoreCase))) { await guildUser.RemoveRoleAsync(roleToAdd); await CommandHandeling.ReplyAsync(context, $"-{roleToAdd.Name}"); return; } await guildUser.AddRoleAsync(roleToAdd); await CommandHandeling.ReplyAsync(context, $"+{roleToAdd.Name}"); } } catch { // ignored } }
public async Task _client_MessageUpdated(Cacheable <IMessage, ulong> messageBefore, SocketMessage messageAfter, ISocketMessageChannel arg3) { if (messageAfter.Author.IsBot) { return; } var after = messageAfter as IUserMessage; if (messageAfter.Content == null) { return; } if (messageAfter.Author is SocketGuildUser userCheck && userCheck.IsMuted) { return; } var before = (messageBefore.HasValue ? messageBefore.Value : null) as IUserMessage; if (before == null) { return; } if (arg3 == null) { return; } if (before.Content == after?.Content) { return; } var list = Global.CommandList; foreach (var t in list) { if (t.UserSocketMsg.Id != messageAfter.Id) { continue; } if (!(messageAfter is SocketUserMessage message)) { continue; } if (t.BotSocketMsg == null) { return; } var context = new ShardedCommandContextCustom(_client, message, "edit"); var argPos = 0; if (message.Channel is SocketDMChannel) { var resultTask = await _commands.ExecuteAsync( context, argPos, _services); if (!resultTask.IsSuccess && !resultTask.ErrorReason.Contains("Unknown command")) { ReplyAsync(context, $"Booole! {resultTask.ErrorReason}"); } return; } var guild = ServerAccounts.GetServerAccount(context.Guild); var account = UserAccounts.GetAccount(context.User, context.Guild.Id); if (message.HasStringPrefix(guild.Prefix, ref argPos) || message.HasStringPrefix(guild.Prefix + " ", ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos) || message.HasStringPrefix(account.MyPrefix + " ", ref argPos) || message.HasStringPrefix(account.MyPrefix, ref argPos)) { var resultTaskk = await _commands.ExecuteAsync( context, argPos, _services); if (!resultTaskk.IsSuccess && !resultTaskk.ErrorReason.Contains("Unknown command")) { ReplyAsync(context, $"Booole! {resultTaskk.ErrorReason}"); } } return; } await Task.CompletedTask; }
public async Task HandleCommandAsync(SocketMessage msg) { var message = msg as SocketUserMessage; if (message == null) { return; } var context = new ShardedCommandContextCustom(_client, message); var argPos = 0; if (message.Author is SocketGuildUser userCheck && userCheck.IsMuted) { return; } if (msg.Author.IsBot) { return; } switch (message.Channel) { case SocketDMChannel _ when context.User.IsBot: return; case SocketDMChannel _: var resultTask = _commands.ExecuteAsync( context, argPos, _services); resultTask.ContinueWith(task => { if (!task.Result.IsSuccess) { Console.ForegroundColor = LogColor("red"); Console.WriteLine( $"{DateTime.Now.ToLongTimeString()} - DM: ERROR '{context.Channel}' {context.User}: {message} || {task.Result.ErrorReason}"); Console.ResetColor(); File.AppendAllText(LogFile, $"{DateTime.Now.ToLongTimeString()} - DM: ERROR '{context.Channel}' {context.User}: {message} || {task.Result.ErrorReason} \n"); if (!task.Result.ErrorReason.Contains("Unknown command")) { ReplyAsync(context, $"Booole! {task.Result.ErrorReason}"); } } else { Console.ForegroundColor = LogColor("white"); Console.WriteLine( $"{DateTime.Now.ToLongTimeString()} - DM: '{context.Channel}' {context.User}: {message}"); Console.ResetColor(); File.AppendAllText(LogFile, $"{DateTime.Now.ToLongTimeString()} - DM: '{context.Channel}' {context.User}: {message} \n"); } }); return; } var guild = ServerAccounts.GetServerAccount(context.Guild); guild.MessagesReceivedAll += 1; ServerAccounts.SaveServerAccounts(); var account = UserAccounts.GetAccount(context.User, context.Guild.Id); if (message.HasStringPrefix(guild.Prefix, ref argPos) || message.HasStringPrefix(guild.Prefix + " ", ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos) || message.HasStringPrefix(account.MyPrefix + " ", ref argPos) || message.HasStringPrefix(account.MyPrefix, ref argPos)) { var resultTask = _commands.ExecuteAsync( context, argPos, _services); resultTask.ContinueWith(task => { if (!task.Result.IsSuccess) { Console.ForegroundColor = LogColor("red"); Console.WriteLine( $"{DateTime.Now.ToLongTimeString()} - ERROR '{context.Channel}' {context.User}: {message} || {task.Result.ErrorReason}"); Console.ResetColor(); File.AppendAllText(LogFile, $"{DateTime.Now.ToLongTimeString()} - ERROR '{context.Channel}' {context.User}: {message} || {task.Result.ErrorReason} \n"); if (!task.Result.ErrorReason.Contains("Unknown command")) { ReplyAsync(context, $"Booole! {task.Result.ErrorReason}"); } } else { Console.ForegroundColor = LogColor("white"); Console.WriteLine( $"{DateTime.Now.ToLongTimeString()} - '{context.Channel}' {context.User}: {message}"); Console.ResetColor(); File.AppendAllText(LogFile, $"{DateTime.Now.ToLongTimeString()} - '{context.Channel}' {context.User}: {message} \n"); } }); } }
public async Task SetServerActivivtyLog(IGuildChannel logChannel = null) { var guild = ServerAccounts.GetServerAccount(Context.Guild); if (logChannel != null) { try { var channel = logChannel; if ((channel as ITextChannel) == null) { await CommandHandeling.ReplyAsync(Context, $"Booole >_< **an error** Maybe I am not an Administrator of this server? I need this permission to access audit, manage channel, emojis and users."); return; } guild.LogChannelId = channel.Id; guild.ServerActivityLog = 1; ServerAccounts.SaveServerAccounts(); var text2 = $"Boole! Now we log everything to {((ITextChannel) channel).Mention}, you may rename and move it.\n"; // $"Btw, you may say `editIgnore 5` and we we will ignore the message where only 5 **characters** have been changed. This will reduce the number of non-spurious logs (you may say any number)"; await CommandHandeling.ReplyAsync(Context, text2); } catch { // await CommandHandeling.ReplyAsync(Context, // $"Booole >_< **an error** Maybe I am not an Administrator of this server? I need this permission to access audit, manage channel, emojis and users."); } return; } switch (guild.ServerActivityLog) { case 1: guild.ServerActivityLog = 0; guild.LogChannelId = 0; ServerAccounts.SaveServerAccounts(); await CommandHandeling.ReplyAsync(Context, $"Octopuses are not logging any activity now **:c**\n"); return; case 0: try { try { var tryChannel = Context.Guild.GetTextChannel(guild.LogChannelId); if (tryChannel.Name != null) { guild.LogChannelId = tryChannel.Id; guild.ServerActivityLog = 1; ServerAccounts.SaveServerAccounts(); var text2 = $"Boole! Now we log everything to {tryChannel.Mention}, you may rename and move it."; await CommandHandeling.ReplyAsync(Context, text2); } } catch { var channel = Context.Guild.CreateTextChannelAsync("OctoLogs"); guild.LogChannelId = channel.Result.Id; guild.ServerActivityLog = 1; ServerAccounts.SaveServerAccounts(); var text = $"Boole! Now we log everything to {channel.Result.Mention}, you may rename and move it."; await CommandHandeling.ReplyAsync(Context, text); } } catch { // await CommandHandeling.ReplyAsync(Context, // $"Booole >_< **an error** Maybe I am not an Administrator of this server? I need this permission to access audit, manage channel, emojis and users."); } break; } }
public async Task ServerStats(ulong guildId = 0) { try { SocketGuild guild; if (guildId == 0) { guild = Context.Guild; } else { guild = Global.Client.GetGuild(guildId); } var userAccounts = UserAccounts.GetOrAddUserAccountsForGuild(guild.Id); var orderedByLvlUsers = userAccounts.OrderByDescending(acc => acc.Lvl).ToList(); var guildAccount = ServerAccounts.GetServerAccount(guild); var orderedByChannels = guildAccount.MessagesReceivedStatisctic.OrderByDescending(chan => chan.Value).ToList(); var aliveUserCount = 0; var activeUserCount = 0; foreach (var t in userAccounts) { if (t.Lvl > 2) { aliveUserCount++; } if (t.Lvl > 20) { activeUserCount++; } } var adminCount = 0; var moderCount = 0; foreach (var t in userAccounts) { var acc = guild.GetUser(t.Id); if (acc == null) { continue; } if (acc.GuildPermissions.Administrator && !acc.IsBot) { adminCount++; } if (acc.GuildPermissions.DeafenMembers && acc.GuildPermissions.ManageMessages && acc.GuildPermissions.ManageChannels && !acc.IsBot) { moderCount++; } } var rolesList = guild.Roles.ToList(); var orderedRoleList = rolesList.OrderByDescending(rl => rl.Members.Count()).ToList(); var embed = new EmbedBuilder(); embed.WithColor(Color.Blue); embed.WithAuthor(Context.User); embed.AddField($"{guild.Name} Statistic", $"**Created:** {Context.Guild.CreatedAt}\n" + $"**Owner:** {Context.Guild.Owner}\n" + $"**Verification Level:** {Context.Guild?.VerificationLevel}\n" + $"**Users:** {Context.Guild.MemberCount}\n" + $"**Alive Users:** {aliveUserCount}\n" + $"**Active Users:** {activeUserCount}\n" + $"**Admins:** {adminCount}\n" + $"**Moderators:** {moderCount}\n"); if (orderedByLvlUsers.Count >= 3 && orderedByChannels.Count >= 4 && orderedRoleList.Count >= 5) { embed.AddField("**______**", "**Top 3 Active users:**\n" + $"{Context.Guild.GetUser(orderedByLvlUsers[0].Id).Mention} - {Math.Round(orderedByLvlUsers[0].Lvl, 2)} LVL\n" + $"{Context.Guild.GetUser(orderedByLvlUsers[1].Id).Mention} - {Math.Round(orderedByLvlUsers[1].Lvl, 2)} LVL\n" + $"{Context.Guild.GetUser(orderedByLvlUsers[2].Id).Mention} - {Math.Round(orderedByLvlUsers[2].Lvl, 2)} LVL\n" + "(to see all - say `top`)\n" + "(to see a user statistic say `stats @user`\n\n" + "**Top 4 Channels:**\n" + $"{Context.Guild.GetTextChannel(Convert.ToUInt64(orderedByChannels[0].Key)).Mention} - {orderedByChannels[0].Value} Messages\n" + $"{Context.Guild.GetTextChannel(Convert.ToUInt64(orderedByChannels[1].Key)).Mention} Messages\n" + $"{Context.Guild.GetTextChannel(Convert.ToUInt64(orderedByChannels[2].Key)).Mention} Messages\n" + $"{Context.Guild.GetTextChannel(Convert.ToUInt64(orderedByChannels[3].Key)).Mention} Messages\n" + $"All Messages: {guildAccount.MessagesReceivedAll}\n" + "(to see all - say `topChan`)\n\n" + "**Top 4 Roles:**\n" + $"{orderedRoleList[1]?.Mention} - {orderedRoleList[1]?.Members.Count()} Members\n" + $"{orderedRoleList[2]?.Mention} - {orderedRoleList[2]?.Members.Count()} Members\n" + $"{orderedRoleList[3]?.Mention} - {orderedRoleList[3]?.Members.Count()} Members\n" + $"{orderedRoleList[4]?.Mention} - {orderedRoleList[4]?.Members.Count()} Members\n" + "(to see all - say `topRoles`"); } else { await ReplyAsync("**ERROR**\n" + "Not everything is displayed:\n" + "You need to have at least 3 users, 4 channels with messages and 4 roles to be able to use this command correctly"); } embed.AddField("**______**", $"**Text Channels Count:** {Context.Guild?.TextChannels.Count}\n" + $"**Voice Channels Count:** {Context.Guild?.VoiceChannels.Count}\n" + $"**All Channels and Category Count:** {Context.Guild?.Channels.Count}\n" + $"**Roles Count:** {Context.Guild.Roles?.Count}\n" + $"**AFK Channel:** {Context.Guild?.AFKChannel} ({Context.Guild?.AFKTimeout} Timeout)\n"); embed.WithThumbnailUrl(guild.IconUrl); embed.WithCurrentTimestamp(); await CommandHandeling.ReplyAsync(Context, embed); } catch { // Console.WriteLine(e.Message); } }
public async Task CheckPrefix() { var guild = ServerAccounts.GetServerAccount(Context.Guild); await CommandHandeling.ReplyAsync(Context, $"boole: `{guild.Prefix}`"); }
public async Task TopByChannels(int page = 1) { try { if (page < 1) { await CommandHandeling.ReplyAsync(Context, "Boole! Try different page <_<"); return; } var guildAccount = ServerAccounts.GetServerAccount(Context.Guild); var allTextChannelsList = Context.Guild.TextChannels.ToList(); var knownTextChannelsList = guildAccount.MessagesReceivedStatisctic.ToList(); const int usersPerPage = 8; var lastPage = 1 + allTextChannelsList.Count / (usersPerPage + 1); if (page > lastPage) { await CommandHandeling.ReplyAsync(Context, $"Boole. Last Page is {lastPage}"); return; } guildAccount.MessagesReceivedStatisctic = new ConcurrentDictionary <string, ulong>(); foreach (var t1 in allTextChannelsList) { ulong num = 0; foreach (var t in knownTextChannelsList) { if (t1.Id.ToString() == t.Key) { num = t.Value; } } guildAccount.MessagesReceivedStatisctic.AddOrUpdate(t1.Id.ToString(), num, (key, value) => num); ServerAccounts.SaveServerAccounts(); } var orderedKnownChannels = guildAccount.MessagesReceivedStatisctic .OrderByDescending(channels => channels.Value).ToList(); var embB = new EmbedBuilder() .WithTitle("Top By Activity In Text Channels:") .WithFooter( $"Page {page}/{lastPage} ● Say \"topChan 2\" to see second page (you can edit previous message)") .WithDescription( "If `Messages Count: 0` that means, I can't read the channel, or no one using it.\n"); page--; for (var i = 1; i <= usersPerPage && i + usersPerPage * page <= orderedKnownChannels.Count; i++) { var num = i - 1 + usersPerPage * page; SocketTextChannel something = null; foreach (var t in allTextChannelsList) { if (orderedKnownChannels[num].Key == t.Id.ToString()) { something = Context.Guild.GetTextChannel(t.Id); } } var cat = "error"; if (something == null) { continue; } if (something.Category != null) { cat = something.Category.Name; } embB.AddField($"#{i + usersPerPage * page} {something.Name}", $"**Messages Count:** {orderedKnownChannels[num].Value}\n" + $"**Average per day:** {orderedKnownChannels[num].Value / 7}\n" + $"**Members:** {something.Users.Count}\n" + $"**Created:** {something.CreatedAt.DateTime}\n" + $"**Category:** {cat}\n" + $"**IsNsfw:** {something.IsNsfw.ToString()}\n" + $"**Position:** {something.Position}\n" + $"**ID:** {something.Id}\n\n**_____**", true); } await CommandHandeling.ReplyAsync(Context, embB); } catch { // Console.WriteLine(e.Message); } }
public async Task _client_MessageUpdated(Cacheable <IMessage, ulong> messageBefore, SocketMessage messageAfter, ISocketMessageChannel arg3) { if (messageAfter.Author.IsBot) { return; } var after = messageAfter as IUserMessage; if (messageAfter.Content == null) { return; } if (messageAfter.Author is SocketGuildUser userCheck && userCheck.IsMuted) { return; } var before = messageBefore.HasValue ? messageBefore.Value : null; if (before == null) { return; } if (arg3 == null) { return; } if (before.Content == after?.Content) { return; } var list = _commandsInMemory.CommandList; foreach (var t in list) { if (t.MessageUserId != messageAfter.Id) { continue; } if (!(messageAfter is SocketUserMessage message)) { continue; } if (t.BotSocketMsg == null) { return; } _global.TotalCommandsChanged++; var account = _accounts.GetAccount(messageAfter.Author); var context = new SocketCommandContextCustom(_client, message, _commandsInMemory, "edit", account.MyLanguage); var argPos = 0; if (message.Channel is SocketDMChannel) { var resultTask = Task.FromResult(await _commands.ExecuteAsync( context, argPos, _services)); await resultTask.ContinueWith(async task => await CommandResults(task, context)); return; } var guild = _serverAccounts.GetServerAccount(context.Guild); if (message.HasStringPrefix(guild.Prefix, ref argPos) || message.HasStringPrefix(guild.Prefix + " ", ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos) || message.HasStringPrefix(account.MyPrefix + " ", ref argPos) || message.HasStringPrefix(account.MyPrefix, ref argPos)) { var resultTask = Task.FromResult(await _commands.ExecuteAsync( context, argPos, _services)); await resultTask.ContinueWith(async task => await CommandResults(task, context)); } return; } await HandleCommandAsync(messageAfter); }