private async Task RunAsync() { try { while (true) { await Task.Delay(_postEvery); int index = _random.Next(0, _messages.Count()); var selected = _messages.ElementAtOrDefault(index); if (selected == null) { await _log.SendMessageAsync("I couldn't find any messages to swindle <:ShibeSad:231546068960018433>"); return; } var mediaIds = await GetMediaIdsAsync(selected); var status = await _twitter.Statuses.UpdateAsync(selected.Resolve(), possibly_sensitive : true, media_ids : mediaIds); await _log.SendMessageAsync("", embed : TwitterHelper.GetPostedEmbed(selected, status.Id)); _ = _manager.LogAsync(status.Id, selected, _messages); _messages.Clear(); } } catch (Exception ex) { await PrettyConsole.LogAsync(LogSeverity.Error, "SwindleService", ex.ToString()); } }
public async Task StartAsync() { await _commands.AddModulesAsync(Assembly.GetEntryAssembly()); _discord.MessageReceived += OnMessageReceivedAsync; await PrettyConsole.LogAsync(LogSeverity.Info, "Services", $"Enabled CommandHandlingService with {_commands.Modules.Count()} modules and {_commands.Commands.Count()} commands"); }
private Task LogAsync(object severity, string source, string message) { if (!Directory.Exists(_logDirectory)) { Directory.CreateDirectory(_logDirectory); } if (!File.Exists(_logFile)) { File.Create(_logFile).Dispose(); } string logText = $"{DateTime.UtcNow.ToString("hh:mm:ss")} [{severity}] {source}: {message}"; File.AppendAllText(_logFile, logText); return(PrettyConsole.LogAsync(severity, source, message)); }
private Task OnLogAsync(LogMessage msg) => PrettyConsole.LogAsync(msg.Severity, msg.Source, msg.Exception?.ToString() ?? msg.Message);
private Task OnLogAsync(LogMessage msg) => PrettyConsole.LogAsync(msg.Severity, msg.Source, msg.Message);