public async Task SetGuildConfig(EventContext e) { using (MikiContext context = new MikiContext()) { GuildUser g = await context.GuildUsers.FindAsync(e.Guild.Id.ToDbLong()); ArgObject arg = e.Arguments.First(); switch (arg.Argument) { case "expneeded": { arg = arg.Next(); if (arg != null) { if (int.TryParse(arg.Argument, out int value)) { g.MinimalExperienceToGetRewards = value; Utils.Embed .SetTitle(e.Locale.GetString("miki_terms_config")) .SetDescription(e.Locale.GetString("guildconfig_expneeded", value)) .ToEmbed().QueueToChannel(e.Channel); } } } break; case "visible": { arg = arg.Next(); if (arg != null) { bool?result = arg.AsBoolean(); if (!result.HasValue) { return; } g.VisibleOnLeaderboards = result.Value; string resourceString = g.VisibleOnLeaderboards ? "guildconfig_visibility_true" : "guildconfig_visibility_false"; Utils.Embed .SetTitle(e.Locale.GetString("miki_terms_config")) .SetDescription(resourceString) .ToEmbed().QueueToChannel(e.Channel); } } break; } await context.SaveChangesAsync(); } }
public async Task SetCommandAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { return; } string commandId = arg.Argument; Event command = e.EventSystem.GetCommandHandler <SimpleCommandHandler>().Commands.FirstOrDefault(x => x.Name == commandId); if (command == null) { e.ErrorEmbed($"{commandId} is not a valid command") .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg.Next(); bool?setValue = arg.AsBoolean(); if (!setValue.HasValue) { setValue = arg.Argument.ToLower() == "yes" || arg.Argument == "1"; } if (!command.CanBeDisabled) { e.ErrorEmbed(e.Locale.GetString("miki_admin_cannot_disable", $"`{commandId}`")) .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg?.Next(); if (arg != null) { if (arg.Argument == "-s") { // TODO: serverwide disable/enable } } using (var context = new MikiContext()) { await command.SetEnabled(context, Global.RedisClient, e.Channel.Id, setValue ?? false); } e.SuccessEmbed(((setValue ?? false) ? e.Locale.GetString("miki_generic_enabled") : e.Locale.GetString("miki_generic_disabled")) + $" {command.Name}") .QueueToChannel(e.Channel); }
public async Task SetModuleAsync(EventContext e) { ArgObject arg = e.Arguments.FirstOrDefault(); if (arg == null) { return; } string moduleName = arg.Argument; Module m = e.EventSystem.GetCommandHandler <SimpleCommandHandler>().Modules.FirstOrDefault(x => x.Name == moduleName); if (m == null) { e.ErrorEmbed($"{arg.Argument} is not a valid module.") .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg?.Next(); bool?setValue = arg.AsBoolean(); if (!setValue.HasValue) { setValue = arg.Argument.ToLower() == "yes" || arg.Argument == "1"; } if (!m.CanBeDisabled && !setValue.Value) { e.ErrorEmbed(e.GetResource("miki_admin_cannot_disable", $"`{moduleName}`")) .ToEmbed().QueueToChannel(e.Channel); return; } arg = arg?.Next(); if (arg != null) { if (arg.Argument == "-s") { // TODO: serverwide disable/enable } } await m.SetEnabled(Global.RedisClient, e.Channel.Id, (setValue ?? false)); Utils.SuccessEmbed(e.Channel.Id, ((setValue ?? false) ? e.GetResource("miki_generic_enabled") : e.GetResource("miki_generic_disabled")) + $" {m.Name}") .QueueToChannel(e.Channel); }