public async Task ChangeStatusCommand(int status) { if (status < 1 || status > 4) { await Respond.SendResponse(Context, "Status can only be between **1-4**!"); return; } BotConfigService.SetDefaultStatus(status); switch (status) { case 1: await Context.Client.SetStatusAsync(UserStatus.Online); break; case 2: await Context.Client.SetStatusAsync(UserStatus.Idle); break; case 3: await Context.Client.SetStatusAsync(UserStatus.DoNotDisturb); break; case 4: await Context.Client.SetStatusAsync(UserStatus.Offline); break; } }
public static async Task Init() { Config = BotConfigService.GetConfig(); LogService.Initialize(); client = new DiscordSocketClient(new DiscordSocketConfig { LogLevel = LogSeverity.Info, MessageCacheSize = 10000, AlwaysDownloadUsers = true, DefaultRetryMode = RetryMode.AlwaysRetry }); SetupEvents(); // Begin invoke of database mute timers Observable .Interval(TimeSpan.FromSeconds(1)) #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed .Subscribe(x => MuteService.UpdateDatabaseTimers()); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await client.LoginAsync(TokenType.Bot, Config.Token); await client.StartAsync(); await SetBotStatuses().ConfigureAwait(false); await Task.Delay(-1); }
private static async Task HandleCommandAsync(SocketMessage messageParam) { if (!(messageParam is SocketUserMessage message)) { return; } int argPos = 0; if (!(message.HasStringPrefix(BotConfigService.GetPrefix(), ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos)) || message.Author.IsBot) { return; } var context = new SocketCommandContext(client, message); await commands.ExecuteAsync( context : context, argPos : argPos, services : services); // LOG LogService.Log.Information($"{context.User.Username}#{context.User.Discriminator}: {context.Message.Content}"); var _record = new LogRecord() { Date = DateTime.Now, Type = LogType.user, Log = $"COMMAND[{context.User.Username}{context.User.Discriminator}]: {context.Message}" }; Database.UpsertRecord(_record); }
public async Task ChangeGameCommand(int status, [Remainder] string game) { if (status < 1 || status > 4) { await Respond.SendResponse(Context, "Status can only be between **1-4**!"); return; } BotConfigService.SetDefaultActivity(status, game); switch (status) { case 1: await Context.Client.SetGameAsync(game, type : ActivityType.Playing); break; case 2: await Context.Client.SetGameAsync(game, type : ActivityType.Listening); break; case 3: await Context.Client.SetGameAsync(game, type : ActivityType.Watching); break; case 4: await Context.Client.SetGameAsync(game, "https://www.twitch.tv/", ActivityType.Streaming); break; default: await Respond.SendResponse(Context, "Please limit activity `1-4`."); break; } }
public async Task ChangePrefixCommand(string newPrefix) { BotConfigService.SetPrefix(newPrefix); await Respond.SendResponse(Context, $"My new prefix is now: `{newPrefix}`!"); }
private static async Task SetBotStatuses() { var _config = BotConfigService.GetConfig(); #region Status int _defaultStatus = 1; if (_config.DefaultStatus < 1 || _config.DefaultStatus > 4) { // Goto default await client.SetStatusAsync(UserStatus.Online); LogService.Log.Warning("Default Status must be a value through 1 and 4 in the Config.json!"); _defaultStatus = 1; } switch (_defaultStatus) { case 1: await client.SetStatusAsync(UserStatus.Online); break; case 2: await client.SetStatusAsync(UserStatus.Idle); break; case 3: await client.SetStatusAsync(UserStatus.DoNotDisturb); break; case 4: await client.SetStatusAsync(UserStatus.Offline); break; } #endregion #region Activity string[] _values = _config.DefaultActivity.Split('|'); if (int.TryParse(_values[0], out var _activityIndex)) { switch (_activityIndex) { case 1: await client.SetGameAsync(_values[1], type : ActivityType.Playing); break; case 2: await client.SetGameAsync(_values[1], type : ActivityType.Listening); break; case 3: await client.SetGameAsync(_values[1], type : ActivityType.Watching); break; case 4: await client.SetGameAsync(_values[1], type : ActivityType.Streaming); break; } } else { LogService.Log.Warning("Could not parse DefaultActivity successfully! Exmample: \"3|My Testing Realm..\""); return; } #endregion }