public async Task InfoCommand() { await ReplyAsync(embed : new EmbedBuilder { Title = "Thorn.aic", Description = $"{_pairs.GetString("INFO")}\n\n**Ping:** {_client.Latency}ms", ThumbnailUrl = _client.CurrentUser.GetAvatarUrl(), Color = new Color(153, 204, 0) }.Build()); }
public ProfileModule(UserAccountsService userAccounts, ILogger <ProfileModule> logger, PairsService pairs, DiscordSocketClient client) { _userAccounts = userAccounts; _logger = logger; _pairs = pairs; _console = client.GetChannel(ulong.Parse(_pairs.GetString("CONSOLE_CHANNEL_ID"))) as SocketTextChannel; }
public ReminderJob(ILogger <ReminderJob> logger, DiscordSocketClient client, PairsService pairs, DataStorageService data) { _logger = logger; _pairs = pairs; _channel = client.GetChannel(ulong.Parse(pairs.GetString("GENERAL_CHANNEL_ID"))) as SocketTextChannel; _daily = data.GetDictionary <string>("Config/daily.json"); }
public async Task SetCommand(AccountItem accountItem, [Remainder] string value) { var account = await _userAccounts.GetAccountAsync(Context.User); if (!IsSafe(account, accountItem, value)) { return; } account[accountItem] = value; await _userAccounts.SaveAccountsAsync(); await Context.Message.AddReactionAsync(Emote.Parse(_pairs.GetString("YES_EMOTE"))); _logger.LogInformation("{ContextUser} changed their profile setting {AccountItem} to: {Value}", Context.User, accountItem, value); await _console.SendMessageAsync(embed : GetProfileUpdateEmbed($"**`{Context.User}`** změnil položku **{accountItem}** na: `{value}`", Context.User as IGuildUser, true)); }
public async Task HelpCommand(int page = 1) { var maxPages = int.Parse(_pairs.GetString("HELP_PAGES")); if (page > maxPages || page <= 0) { page = 1; } var embed = new EmbedBuilder { Title = _pairs.GetString($"HELP_TITLE_{page}"), Description = _pairs.GetString($"HELP_DESCRIPTION_{page}"), Color = Color.LightGrey, Footer = new EmbedFooterBuilder().WithText($"Strana {page} z {maxPages}") }.Build(); await ReplyAsync(embed : embed); }
public async Task Execute(IJobExecutionContext context) { var day = DateTime.Now; var description = _daily[day.ToString("dd MM")] + $"\n\nPřeji hezký den {_pairs.GetString("AGRLOVE_EMOTE")}"; var embed = new EmbedBuilder { Title = "Krásné dobré ráno!", Description = description, ThumbnailUrl = "https://cdn.discordapp.com/attachments/537064369725636611/733080455217283131/calendar-flat.png", Color = Color.Green }.Build(); await _channel.SendMessageAsync(embed : embed); _logger.LogInformation("Sent daily reminder for {Day}", day.Date); }
private async Task PostLeaderboard(IEnumerable <UserAccount> accounts, int page, PointType?type = null) { var range = SplitList(accounts, _leaderboardSize); if (page < 1 || page > range.Count) { page = 1; } var leaderboard = new StringBuilder(); int skippedIds = 0; foreach (var account in range[page - 1].Select((value, index) => new { value, index })) { var user = Context.Guild.GetUser(account.value.Id); // Skip to the next iteration if the user is no longer in the server if (user == null) { skippedIds++; continue; } // No PointType defined, use the whole leaderboard if (type == null) { if (account.value.Id != 227114285074087938) { leaderboard.Append( $"**`{(page - 1) * _leaderboardSize + account.index + 1 - skippedIds}.`** {user.Nickname ?? user.Username} - " + $"**{account.value.Points.Sum(x => x.Value)}**\n"); } else // Uty { leaderboard.Append( $"**`{(page - 1) * _leaderboardSize + account.index + 1 - skippedIds}.`** {user.Nickname ?? user.Username} - " + "**ano**\n"); } } // PointType defined, use only that leaderboard else { if (account.value.Id != 227114285074087938 || type != PointType.Translation) { leaderboard.Append( $"**`{(page - 1) * _leaderboardSize + account.index + 1 - skippedIds}.`** {user.Nickname ?? user.Username} - " + $"**{account.value.Points[type.GetValueOrDefault()]}**\n"); } else // Uty { leaderboard.Append( $"**`{(page - 1) * _leaderboardSize + account.index + 1 - skippedIds}.`** {user.Nickname ?? user.Username} - " + "**ano**\n"); } } } var title = type == null ? _pairs.GetString("LEADERBOARD_TITLE") : _pairs.GetString($"LEADERBOARD_{type.ToString()?.ToUpper()}_TITLE"); await ReplyAsync(embed : new EmbedBuilder { Title = title, Description = leaderboard.ToString(), Footer = new EmbedFooterBuilder().WithText($"Strana {page} z {range.Count}"), Color = Color.Blue }.Build()); }
public async Task AssignPointsCommand(PointType type) { if (!_authorizedUsers.Contains(Context.User.Id)) { return; } // ReSharper disable once MethodHasAsyncOverload _webClient.DownloadFile(new Uri(Context.Message.Attachments.First().Url), "points"); var file = await File.ReadAllLinesAsync("points"); string typeString; string pattern; switch (type) { case PointType.Translation: pattern = "([0-9]{18}),Bodů,(\"[0-9]*,[0-9]*|[0-9]*)"; typeString = "Překladatelské"; File.Move("points", "translation-points", true); break; case PointType.Writing: pattern = "([0-9]{18}),([0-9]*)"; typeString = "Spisovatelské"; File.Move("points", "writing-points", true); break; case PointType.Correction: pattern = "([0-9]{18});([0-9]*(,[0-9]*|))"; typeString = "Korektorské"; File.Move("points", "correction-points", true); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } var matches = file.Select(s => Regex.Match(s, pattern)).ToList(); var changes = new StringBuilder($"**{typeString.ToUpper()} BODY**\n\n"); var numOfChanges = 0; foreach (var match in matches.Where(match => match.Success)) { ulong id; float points; try { id = Convert.ToUInt64(match.Groups[1].Value); points = SanitizePointValue(match.Groups[2].Value); } catch (InvalidOperationException) { // Row was formatted weirdly or data couldn't be converted // Either way we continue continue; } var account = await _accounts.GetAccountAsync(id); if (type == PointType.Translation && account.Id == 227114285074087938) { points = 999999; // Utylike } // ReSharper disable once CompareOfFloatsByEqualityOperator if (account.Points[type] == points) { continue; } changes.Append($"`{account.Id}` {account.Points[type]} -> {points}\n"); account.Points[type] = points; numOfChanges++; } changes.Append($"\n{typeString} body aktualizovány u {numOfChanges} lidí. Díky, " + $"{Context.User.Username} {_pairs.GetString("AGRLOVE_EMOTE")}"); var message = changes.ToString(); if (numOfChanges == 0) { message = "Nejspíš si mi nahrál špatný soubor. Podívej se a zkus to znovu!"; } _logger.LogInformation("Updated points: {Message}", message); await _accounts.UpdateRanks(type); await ReplyAsync(message); if (!(_client.GetChannel(ulong.Parse(_pairs.GetString("LOGGING_CHANNEL_ID"))) is SocketTextChannel o5) || numOfChanges == 0) { return; } await o5.SendMessageAsync(message); }