public static void Load() { string path = Directories.AppendPath(Directories.saves, "Accounts"); string filePath = Path.Combine(path, "accounts.xml"); ServerAccounts.Load(filePath); }
/// <summary> /// Configures the SQL Server services. /// </summary> /// <param name="services">The services collection to register services in.</param> /// <param name="configuration">The SQL Server configuration.</param> public static void Configure(IServiceCollection services, ISqlServerConfiguration configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } // register configuration RegisterConfiguration(services: services, configuration: configuration); // Register shared services. RegisterDatabaseServices(services); SendTransactions.Configure(services); EventTransactions.Configure(services); ServerAccounts.Configure(services); ObjectLocking.Configure(services); FaucetTracking.Configure(services); Player.Configure(services); GameSupport.Configure(services); }
public static void Init() { var db = new AppDatabase.DbConnection(); var dbConn = db.Connect(); ServerAccounts = new ServerAccounts {Db = db}; }
public CheckForMute(ServerAccounts serverAccounts, UserAccounts accounts, Global global) { _serverAccounts = serverAccounts; _accounts = accounts; _global = global; CheckTimer(); }
public CheckBirthday(ServerAccounts serverAccounts, UserAccounts accounts, Global global) { _serverAccounts = serverAccounts; _accounts = accounts; _global = global; CheckTimer(); }
public CheckToDeleteVoiceChannel(ServerAccounts serverAccounts, UserAccounts accounts, Global global) { _serverAccounts = serverAccounts; _accounts = accounts; _global = global; CheckTimer(); }
public ServerSetup(UserAccounts accounts, ServerAccounts serverAccounts, Global global, SecureRandom secureRandom) { _accounts = accounts; _serverAccounts = serverAccounts; _global = global; _secureRandom = secureRandom; }
public async Task Help() { var serverAccount = ServerAccounts.GetAccount(Context.Guild); var embed = new EmbedBuilder(); embed.WithTitle("Page 1/2"); embed.WithDescription($"**Server Prefix:** `{serverAccount.Prefix}`"); embed.WithImageUrl("https://i.imgur.com/9ImiHyn.png"); RestUserMessage msg = await Context.Channel.SendMessageAsync("", false, embed.Build()); Global.MessageToToTrack = msg.Id; var one = new Emoji("\U00000031\U000020e3"); var two = new Emoji("\U00000032\U000020e3"); var delete = new Emoji("\U000023f9"); var questionmark = new Emoji("\U00002754"); await msg.AddReactionAsync(one); await msg.AddReactionAsync(two); await msg.AddReactionAsync(delete); await msg.AddReactionAsync(questionmark); }
public async Task AdminHelp() { if (Context.Channel is IDMChannel) { await Context.Channel.SendMessageAsync($"https://i.imgur.com/6ifbG8t.png"); return; } SocketGuild target = Context.Guild; var serverAccount = ServerAccounts.GetAccount((SocketGuild)target); var prefix = serverAccount.Prefix; if (!File.Exists($"Resources/{Context.Guild.Id}Admin.png")) { var converter = new HtmlConverter(); var generationStrings = new HelpGenerationFiles(); string css = generationStrings.HelpCss(); string html = String.Format(generationStrings.AdminHelpHtml(prefix)); int width = 520; var bytes = converter.FromHtmlString(css + html, width, CoreHtmlToImage.ImageFormat.Png); File.WriteAllBytes($"Resources/{Context.Guild.Id}Admin.png", bytes); } await Context.Channel.SendFileAsync($"Resources/{Context.Guild.Id}Admin.png"); }
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 SetPrefix(string prefix) { SocketGuild target = Context.Guild; var serverAccount = ServerAccounts.GetAccount((SocketGuild)target); serverAccount.Prefix = prefix; ServerAccounts.SaveAccounts(); var embed = new EmbedBuilder(); embed.WithTitle($"Prefix changed to `{prefix}` !"); embed.WithDescription($"You can still use @ModernWarfareStats as the Prefix to execute commands."); embed.AddField("Example:", "<@695738324425375805> help"); embed.WithColor(new Discord.Color(128, 213, 255)); await Context.Channel.SendMessageAsync("", false, embed.Build()); var converter = new HtmlConverter(); var generationStrings = new HelpGenerationFiles(); string css = generationStrings.HelpCss(); string html = String.Format(generationStrings.HelpHtml(serverAccount.Prefix)); int width = 520; var bytes = converter.FromHtmlString(css + html, width, CoreHtmlToImage.ImageFormat.Png); File.WriteAllBytes($"Resources/{Context.Guild.Id}.png", bytes); css = generationStrings.HelpCss(); html = String.Format(generationStrings.AdminHelpHtml(serverAccount.Prefix)); width = 520; bytes = converter.FromHtmlString(css + html, width, CoreHtmlToImage.ImageFormat.Png); File.WriteAllBytes($"Resources/{Context.Guild.Id}Admin.png", bytes); }
public async Task RegisterBN([Remainder] string gameUsername) { if (gameUsername.Contains("#")) { gameUsername = gameUsername.Replace("#", "%23"); } else { var errorEmbed = new EmbedBuilder(); errorEmbed.WithTitle("Ouch! An error occurred."); errorEmbed.WithDescription("Invalid BattleNet username."); errorEmbed.WithColor(255, 0, 0); await Context.Channel.SendMessageAsync("", false, errorEmbed.Build()); return; } var jsonAsString = await ApiProcessor.GetUser($"https://api.tracker.gg/api/v2/warzone/standard/profile/battlenet/{gameUsername}"); var serverAccount = ServerAccounts.GetAccount(Context.Guild); var account = UserAccounts.GetAccount(Context.User); account.Platform = "battlenet"; account.GameUsername = gameUsername; UserAccounts.SaveAccounts(); var embed = new EmbedBuilder(); embed.WithDescription($"**Server Prefix:** `{serverAccount.Prefix}`"); embed.WithImageUrl("https://i.imgur.com/0hI99PO.png"); await Context.Channel.SendMessageAsync("", false, embed.Build()); }
public static void Save(WorldSaveEventArgs e) { string path = Directories.AppendPath(Directories.saves, "Accounts"); string filePath = Path.Combine(path, "accounts.xml"); ServerAccounts.Save(filePath); }
public async Task JoinedServer(SocketGuild guild) { await Task.Run(() => { var target = guild; ServerAccounts.GetAccount(target); }); }
public static void Init() { var db = new AppDatabase.DbConnection(); var dbConn = db.Connect(); ServerAccounts = new ServerAccounts { Db = db }; }
static UserAccounts() { var guildList = ServerAccounts.GetAllServerAccounts(); foreach (var guild in guildList) { UserAccountsDictionary.GetOrAdd(guild.ServerId, x => DataStorage.LoadAccountSettings(guild.ServerId).ToList()); } }
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 Stats([Remainder] string arg = "") { SocketUser target = null; var mentionUser = Context.Message.MentionedUsers.FirstOrDefault(); target = mentionUser ?? Context.User; var account = UserAccounts.GetAccount(target); var serverAccount = ServerAccounts.GetAccount(Context.Guild); if (string.IsNullOrEmpty(account.GameUsername)) { var errorEmbed = new EmbedBuilder(); errorEmbed.WithTitle("Ouch! An error occurred."); errorEmbed.WithDescription($"User not registered."); errorEmbed.WithColor(255, 0, 0); await Context.Channel.SendMessageAsync("", false, errorEmbed.Build()); return; } var jsonAsString = await ApiProcessor.GetUser($"https://api.tracker.gg/api/v2/modern-warfare/standard/profile/{account.Platform}/{account.GameUsername}"); var apiData = JsonConvert.DeserializeObject <ModerWarfareApiOutput>(jsonAsString); var name = apiData.Data.PlatformInfo.PlatformUserHandle; var pfp = apiData.Data.PlatformInfo.AvatarUrl; var playTime = apiData.Data.Segment[0].Stats.TimePlayedTotal.DisplayValue; var matches = apiData.Data.Segment[0].Stats.TotalGamesPlayed.DisplayValue; var levelImg = apiData.Data.Segment[0].Stats.Level.Metadata.IconUrl; var level = apiData.Data.Segment[0].Stats.Level.DisplayValue; var levelper = apiData.Data.Segment[0].Stats.LevelProgression.DisplayValue; var kd = apiData.Data.Segment[0].Stats.KdRatio.DisplayValue; var kills = apiData.Data.Segment[0].Stats.Kills.DisplayValue; var WinPer = apiData.Data.Segment[0].Stats.WlRatio.DisplayValue; var wins = apiData.Data.Segment[0].Stats.Wins.DisplayValue; var bestKillsreak = apiData.Data.Segment[0].Stats.LongestKillstreak.DisplayValue; var losses = apiData.Data.Segment[0].Stats.Losses.DisplayValue; var deaths = apiData.Data.Segment[0].Stats.Deaths.DisplayValue; var avgLife = apiData.Data.Segment[0].Stats.AverageLife.DisplayValue; var assists = apiData.Data.Segment[0].Stats.Assists.DisplayValue; var score = apiData.Data.Segment[0].Stats.CareerScore.DisplayValue; var accuracy = apiData.Data.Segment[0].Stats.Accuracy.DisplayValue; var headshotaccuracy = apiData.Data.Segment[0].Stats.HeadshotPercentage.DisplayValue; var converter = new HtmlConverter(); var generationStrings = new StatsGenerationFiles(); string css = generationStrings.MultiplayerCss(levelper); string html = String.Format(generationStrings.MultiplayerHtml(name, pfp, playTime, matches, levelImg.ToString(), level, levelper, kd, kills, WinPer, wins, bestKillsreak, losses, deaths, avgLife, assists, score, accuracy, headshotaccuracy)); int width = 520; var bytes = converter.FromHtmlString(css + html, width, CoreHtmlToImage.ImageFormat.Png); File.WriteAllBytes("Resources/Stats.png", bytes); await Context.Channel.SendFileAsync(new MemoryStream(bytes), "Resources/Stats.png"); }
public async Task BuildExistingServer() { var guild = Global.Client.Guilds.ToList(); foreach (var t in guild) { ServerAccounts.GetServerAccount(t); } await CommandHandeling.ReplyAsync(Context, "Севера бобавлены, бууууль!"); }
public static void Init() { var db = new DbConnection(Config.GetDatabasePath(), DbProtection.GetDatabaseKey()); CryptoKeys = new CryptoKeys { Db = db }; Databases = new Databases { Db = db }; DatabasesEntries = new DatabasesEntries { Db = db }; DatabasesEntriesData = new DatabasesEntriesData { Db = db }; DatabasesEntriesDataSync = new DatabasesEntriesDataSync { Db = db }; DatabasesEntriesDataVersions = new DatabasesEntriesDataVersions { Db = db }; DatabasesEntries = new DatabasesEntries { Db = db }; DatabasesGroups = new DatabasesGroups { Db = db }; DatabasesGroupsMeta = new DatabasesGroupsMeta { Db = db }; DatabasesGroupsMetaSync = new DatabasesGroupsMetaSync { Db = db }; DatabasesGroupsMetaVersions = new DatabasesGroupsMetaVersions { Db = db }; DatabasesMeta = new DatabasesMeta { Db = db }; DatabasesMetaSync = new DatabasesMetaSync { Db = db }; DatabasesMetaVersions = new DatabasesMetaVersions { Db = db }; ServerAccounts = new ServerAccounts { Db = db }; ServerManagementAccounts = new ServerManagementAccounts { Db = db }; }
public CommandHandling(CommandService commands, DiscordShardedClient client, UserAccounts accounts, ServerAccounts serverAccounts, CommandsInMemory commandsInMemory, Scope scope, LoginFromConsole log, Global global) { _commands = commands; _services = scope; _log = log; _global = global; _client = client; _accounts = accounts; _serverAccounts = serverAccounts; _commandsInMemory = commandsInMemory; }
// [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, предупреждение"); } }
#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 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); }
private async Task HandleCommandAsync(SocketMessage socketMessage) { var msg = socketMessage as SocketUserMessage; if (msg == null) { return; } var context = new SocketCommandContext(_client, msg); if (context.User.IsBot) { return; } var serverPrefix = ""; if (!(context.Channel is IDMChannel)) { serverPrefix = ServerAccounts.GetAccount((SocketGuild)context.Guild).Prefix; } else { serverPrefix = ">"; } int argPos = 0; if (msg.HasStringPrefix(serverPrefix, ref argPos) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos)) { var result = await _service.ExecuteAsync(context, argPos, null); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { Console.ForegroundColor = ConsoleColor.Green; Console.Write(DateTimeOffset.UtcNow.ToString("[d.MM.yyyy HH:mm:ss] ")); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(result.ErrorReason); Console.ForegroundColor = ConsoleColor.White; var embed = new EmbedBuilder(); embed.WithTitle("Ouch! An error occurred."); embed.WithDescription(result.ErrorReason); embed.WithColor(255, 0, 0); await context.Channel.SendMessageAsync("", false, embed.Build()); } } }
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 RegisterXBL([Remainder] string gameUsername) { var jsonAsString = await ApiProcessor.GetUser($"https://api.tracker.gg/api/v2/warzone/standard/profile/xbl/{gameUsername}"); var serverAccount = ServerAccounts.GetAccount(Context.Guild); var account = UserAccounts.GetAccount(Context.User); account.Platform = "xbl"; account.GameUsername = gameUsername; UserAccounts.SaveAccounts(); var embed = new EmbedBuilder(); embed.WithDescription($"**Server Prefix:** `{serverAccount.Prefix}`"); embed.WithImageUrl("https://i.imgur.com/0hI99PO.png"); await Context.Channel.SendMessageAsync("", false, embed.Build()); }
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 ServerUpd() { await ReplyAsync("324"); var serverAccount = ServerAccounts.GetAllServerAccounts(); foreach (var t in serverAccount) { var rooms = t.MessagesReceivedStatisctic.ToList(); foreach (var room in rooms) { if (!ulong.TryParse(room.Key, out _)) { t.MessagesReceivedStatisctic.TryRemove($"{room.Key}", out _); } } } }