public async Task Bean(IGuildUser user, [Remainder] string reason = null) { using var Database = new SkuldDbContextFactory().CreateDbContext(); var usr = Database.Users.Find(user.Id); if (usr.Flags.IsBitSet(DiscordUtilities.Banned)) { usr.Flags -= DiscordUtilities.Banned; usr.BanReason = null; await EmbedExtensions.FromSuccess(SkuldAppContext.GetCaller(), $"Un-beaned {user.Mention}", Context) .QueueMessageAsync(Context).ConfigureAwait(false); } else { if (reason == null) { await EmbedExtensions.FromError($"{nameof(reason)} needs a value", Context) .QueueMessageAsync(Context).ConfigureAwait(false); return; } usr.Flags += DiscordUtilities.Banned; usr.BanReason = reason; await EmbedExtensions.FromSuccess(SkuldAppContext.GetCaller(), $"Beaned {user.Mention} for reason: `{reason}`", Context) .QueueMessageAsync(Context).ConfigureAwait(false); } await Database.SaveChangesAsync().ConfigureAwait(false); }
public async Task LMGTFY([Remainder] string query) { using var Database = new SkuldDbContextFactory().CreateDbContext(); var prefix = (await Database.InsertOrGetGuildAsync(Context.Guild).ConfigureAwait(false)).Prefix ?? Configuration.Prefix; string url = "https://lmgtfy.com/"; var firstPart = query.Split(" ")[0]; url = (firstPart.ToLowerInvariant()) switch { "b" or "bing" => url + "?s=b&q=" + query.ReplaceFirst(firstPart, "").Replace(" ", "%20"), "y" or "yahoo" => url + "?s=y&q=" + query.ReplaceFirst(firstPart, "").Replace(" ", "%20"), "a" or "aol" => url + "?a=b&q=" + query.ReplaceFirst(firstPart, "").Replace(" ", "%20"), "k" or "ask" => url + "?k=b&q=" + query.ReplaceFirst(firstPart, "").Replace(" ", "%20"), "d" or "duckduckgo" or "ddg" => url + "?s=d&q=" + query.ReplaceFirst(firstPart, "").Replace(" ", "%20"), "g" or "google" => url + "?s=g&q=" + query.ReplaceFirst(firstPart, "").Replace(" ", "%20"), _ => url + "?q=" + query.Replace(" ", "%20"), }; if (url != "https://lmgtfy.com/") { await url.QueueMessageAsync(Context).ConfigureAwait(false); } else { await EmbedExtensions.FromError($"Ensure your parameters are correct, example: `{prefix}lmgtfy g How to use lmgtfy`", Context).QueueMessageAsync(Context).ConfigureAwait(false); StatsdClient.DogStatsd.Increment("commands.errors", 1, 1, new[] { "generic" }); } }
public async Task CreateKeys(ulong amount) { using var db = new SkuldDbContextFactory().CreateDbContext(); StringBuilder message = new StringBuilder($"Keycodes:"); message.AppendLine(); for (ulong x = 0; x < amount; x++) { var key = new DonatorKey { KeyCode = Guid.NewGuid() }; db.DonatorKeys.Add(key); message.AppendLine($"Keycode: {key.KeyCode}"); } DogStatsd.Increment("donatorkeys.generated", (int)amount); await db.SaveChangesAsync().ConfigureAwait(false); await message.QueueMessageAsync( Context, type : Services.Messaging.Models.MessageType.DMS ).ConfigureAwait(false); }
public async Task CheckKey(Guid key) { using var db = new SkuldDbContextFactory().CreateDbContext(); var donorkey = db.DonatorKeys .FirstOrDefault(x => x.KeyCode == key); StringBuilder message = new StringBuilder(); message .Append("Key: `") .Append(key) .Append("` "); if (donorkey != null) { message .Append("is") .Append(donorkey.Redeemed ? "" : " not ") .Append("redeemed"); } else { message.Append("doesn't exist"); } await message.QueueMessageAsync(Context).ConfigureAwait(false); }
public async Task CheckDonatorStatus(IUser user) { using var Database = new SkuldDbContextFactory().CreateDbContext(); var keys = Database.DonatorKeys.ToList().Where(x => x.Redeemer == user.Id); StringBuilder message = new StringBuilder(); message.Append(user.Mention) .Append(" is "); if (keys.Any()) { var keysordered = keys.OrderBy(x => x.RedeemedWhen); var amount = 365 * keys.Count(); var time = keysordered.LastOrDefault().RedeemedWhen.FromEpoch(); time = time.AddDays(amount); message.Append("a donator until ") .Append(time.ToDMYString()); } else { message.Append("not a donator 🙁"); } await message.QueueMessageAsync(Context).ConfigureAwait(false); }
public static async Task ProcessExperienceAsync(ICommandContext context, Guild sguild) { if (sguild is null) { return; } using var Database = new SkuldDbContextFactory().CreateDbContext(); if (!Database.Features.Any(x => x.Id == sguild.Id)) { Database.Features.Add(new GuildFeatures { Id = sguild.Id }); await Database.SaveChangesAsync().ConfigureAwait(false); } GuildFeatures features = Database.Features.Find(sguild.Id); if (features.Experience) { await ExperienceService.HandleExperienceAsync(context); } }
public static async Task ProcessCustomCommand(ICommandContext context, Guild sguild) { if (sguild is null) { return; } using var Database = new SkuldDbContextFactory().CreateDbContext(); if (sguild is not null) { GuildModules modules; if (!Database.Modules.Any(x => x.Id == sguild.Id)) { Database.Modules.Add(new GuildModules { Id = sguild.Id }); await Database.SaveChangesAsync().ConfigureAwait(false); } modules = Database.Modules.Find(sguild.Id); if (modules.Custom) { await CustomCommandService.HandleCustomCommandAsync(context, SkuldApp.Configuration); } } }
private EmbedBuilder DoAction(string gif, string action, string target) { List <ulong> prune = new List <ulong>(); { using SkuldDbContext Database = new SkuldDbContextFactory().CreateDbContext(null); if (Context.Message.MentionedUsers.Any()) { foreach (var mentionedUser in Context.Message.MentionedUsers) { var res = Database.BlockedActions.FirstOrDefault(x => x.Blocker == mentionedUser.Id && x.Blockee == Context.User.Id); if (res != null) { prune.Add(mentionedUser.Id); } } } } foreach (var id in prune) { target.PruneMention(id); } return(new EmbedBuilder() .WithImageUrl(gif) .WithTitle(action.CapitaliseFirstLetter()) .WithDescription(target) .WithRandomColor() .AddAuthor(Context.Client) .AddFooter(Context)); }
public async Task Profile([Remainder] IGuildUser user = null) { using var Database = new SkuldDbContextFactory().CreateDbContext(); if (user is not null && (user.IsBot || user.IsWebhook)) { await EmbedExtensions.FromError(DiscordUtilities.NoBotsString, Context).QueueMessageAsync(Context).ConfigureAwait(false); return; } if (user is null) { user = Context.User as IGuildUser; } await Database.InsertOrGetUserAsync(user).ConfigureAwait(false); var profileImage = await ApiClient.GetProfileCardAsync(Context.User.Id, Context.Guild.Id); if (profileImage is not null) { await "".QueueMessageAsync(Context, filestream: profileImage, filename: "image.png").ConfigureAwait(false); } }
public async Task ViewImage() { var msg = await "Please wait... Generating the place" .QueueMessageAsync(Context) .ConfigureAwait(false); using var Database = new SkuldDbContextFactory().CreateDbContext(); List <PixelData> pixelData = Database.PlacePixelData .AsNoTracking() .ToList(); int size = SkuldAppContext.PLACEIMAGESIZE * 4; using Bitmap image = pixelData .WritePixelDataBitmap() .ResizeBitmap(size, size); using MemoryStream outputStream = new(); image.Save(outputStream, ImageFormat.Png); outputStream.Position = 0; await msg.DeleteAsync().ConfigureAwait(false); await Context.Channel.SendFileAsync(outputStream, "theplace.png").ConfigureAwait(false); }
private static async Task Bot_JoinedGuild( SocketGuild arg ) { DogStatsd.Increment("guilds.joined"); Log.Verbose(Key, $"Just left {arg}", null); try { using var database = new SkuldDbContextFactory().CreateDbContext(); await SkuldApp.DiscordClient.SendDataAsync( SkuldApp.Configuration.IsDevelopmentBuild, SkuldApp.Configuration.DiscordGGKey, SkuldApp.Configuration.DBotsOrgKey, SkuldApp.Configuration.B4DToken ) .ConfigureAwait(false); await database.InsertOrGetGuildAsync( arg, SkuldApp.Configuration.Prefix, SkuldApp.MessageServiceConfig.MoneyName, SkuldApp.MessageServiceConfig.MoneyIcon ) .ConfigureAwait(false); //MessageQueue.CheckForEmptyGuilds = true; } catch (Exception ex) { Log.Error("UsrJoin", ex.Message, null, ex); } }
private static async Task Bot_UserUpdated( SocketUser arg1, SocketUser arg2 ) { if (arg1.IsBot || arg1.IsWebhook) { return; } try { using SkuldDbContext database = new SkuldDbContextFactory() .CreateDbContext(); Skuld.Models.User suser = await database .InsertOrGetUserAsync(arg2) .ConfigureAwait(false); if (!suser.IsUpToDate(arg2)) { suser.AvatarUrl = arg2.GetAvatarUrl() ?? arg2.GetDefaultAvatarUrl(); suser.Username = arg2.Username; await database.SaveChangesAsync().ConfigureAwait(false); } } catch (Exception ex) { Log.Error("UsrJoin", ex.Message, null, ex); } }
public async Task GetFlags([Remainder] IUser user = null) { if (user == null) { user = Context.User; } using var Database = new SkuldDbContextFactory().CreateDbContext(); var dbUser = await Database.InsertOrGetUserAsync(user).ConfigureAwait(false); List <BotAccessLevel> flags = new List <BotAccessLevel>(); if (dbUser.Flags.IsBitSet(DiscordUtilities.BotCreator)) { flags.Add(BotAccessLevel.BotOwner); } if (dbUser.Flags.IsBitSet(DiscordUtilities.BotAdmin)) { flags.Add(BotAccessLevel.BotAdmin); } if (!dbUser.IsDonator) { flags.Add(BotAccessLevel.BotDonator); } if (dbUser.Flags.IsBitSet(DiscordUtilities.BotTester)) { flags.Add(BotAccessLevel.BotTester); } flags.Add(BotAccessLevel.Normal); await $"{user.Mention} has the flags `{string.Join(", ", flags)}`".QueueMessageAsync(Context).ConfigureAwait(false); }
private static async Task Bot_GuildUpdated( SocketGuild arg1, SocketGuild arg2 ) { try { using SkuldDbContext Database = new SkuldDbContextFactory() .CreateDbContext(); var sguild = await Database.InsertOrGetGuildAsync(arg2) .ConfigureAwait(false); if (sguild.Name == null || !sguild.Name.Equals(arg2.Name)) { sguild.Name = arg2.Name; } if (sguild.IconUrl == null || !sguild.IconUrl.Equals(arg2.IconUrl)) { sguild.IconUrl = arg2.IconUrl; } await Database.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { Log.Error("UsrJoin", ex.Message, null, ex); } }
public async Task DropGuild(ulong guildId) { using var database = new SkuldDbContextFactory().CreateDbContext(); await database.DropGuildAsync(guildId).ConfigureAwait(false); await database.SaveChangesAsync().ConfigureAwait(false); }
public static async Task HandleSideTasksAsync(ICommandContext context) { using var Database = new SkuldDbContextFactory().CreateDbContext(); Guild sguild = null; if (context.Guild != null) { sguild = await Database.InsertOrGetGuildAsync(context.Guild) .ConfigureAwait(false); } if (sguild != null) { if (!Database.Features.Any(x => x.Id == sguild.Id)) { Database.Features.Add(new GuildFeatures { Id = sguild.Id }); await Database.SaveChangesAsync().ConfigureAwait(false); } GuildFeatures features = Database.Features.Find(sguild.Id); if (features.Experience) { _ = Task.Run(() => ExperienceService.HandleExperienceAsync(context)); } if (!Database.Modules.Any(x => x.Id == sguild.Id)) { Database.Modules.Add(new GuildModules { Id = sguild.Id }); await Database.SaveChangesAsync().ConfigureAwait(false); } GuildModules modules; if (!Database.Modules.Any(x => x.Id == sguild.Id)) { Database.Modules.Add(new GuildModules { Id = sguild.Id }); await Database.SaveChangesAsync().ConfigureAwait(false); } modules = Database.Modules.Find(sguild.Id); if (modules.Custom) { _ = Task.Run(() => CustomCommandService.HandleCustomCommandAsync(context, SkuldApp.Configuration)); } } }
public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { using var Database = new SkuldDbContextFactory().CreateDbContext(); if (Database.IsConnected) { return(Task.FromResult(PreconditionResult.FromSuccess())); } return(Task.FromResult(PreconditionResult.FromError("Command requires an active Database Connection"))); }
public async Task SellKey(Guid key) { using var Database = new SkuldDbContextFactory().CreateDbContext(); if (Database.DonatorKeys.ToList().Any(x => x.KeyCode == key)) { var dbKey = Database.DonatorKeys.ToList().FirstOrDefault(x => x.KeyCode == key); if (dbKey.Redeemed) { await EmbedExtensions .FromError("Donator Module", "Can't sell a redeemed key", Context) .QueueMessageAsync(Context) .ConfigureAwait(false); } else { Database.DonatorKeys.Remove(dbKey); await Database.SaveChangesAsync().ConfigureAwait(false); var usr = await Database.InsertOrGetUserAsync(Context.User).ConfigureAwait(false); TransactionService.DoTransaction(new TransactionStruct { Amount = 25000, Receiver = usr }); await Database.SaveChangesAsync().ConfigureAwait(false); await EmbedExtensions .FromSuccess("Donator Module", $"You just sold your donator key for {SkuldApp.MessageServiceConfig.MoneyIcon}{25000.ToFormattedString()}", Context) .QueueMessageAsync(Context) .ConfigureAwait(false); DogStatsd.Increment("donatorkeys.sold"); } } else { await EmbedExtensions .FromError("Donator Module", "Key doesn't exist", Context) .QueueMessageAsync(Context) .ConfigureAwait(false); } }
public async Task RedeemKey(Guid key) { using var Database = new SkuldDbContextFactory().CreateDbContext(); if (Database.DonatorKeys.ToList().Any(x => x.KeyCode == key)) { var dbKey = Database.DonatorKeys.ToList().FirstOrDefault(x => x.KeyCode == key); if (dbKey.Redeemed) { await EmbedExtensions .FromError("Donator Module", "Key already redeemed", Context) .QueueMessageAsync(Context) .ConfigureAwait(false); } else { dbKey.Redeemed = true; dbKey.Redeemer = Context.User.Id; dbKey.RedeemedWhen = DateTime.UtcNow.ToEpoch(); await Database.SaveChangesAsync().ConfigureAwait(false); var usr = await Database.InsertOrGetUserAsync(Context.User).ConfigureAwait(false); usr.Flags += DiscordUtilities.BotDonator; await Database.SaveChangesAsync().ConfigureAwait(false); await EmbedExtensions .FromSuccess("Donator Module", "You are now a donator", Context) .QueueMessageAsync(Context) .ConfigureAwait(false); DogStatsd.Increment("donatorkeys.redeemed"); } } else { await EmbedExtensions .FromError("Donator Module", "Key doesn't exist", Context) .QueueMessageAsync(Context) .ConfigureAwait(false); } }
private static async Task Shard_MessagesBulkDeleted( IReadOnlyCollection <Cacheable <IMessage, ulong> > arg1, ISocketMessageChannel arg2 ) { using var Database = new SkuldDbContextFactory().CreateDbContext(); if (arg2 is IGuildChannel guildChannel) { var gld = await Database .InsertOrGetGuildAsync(guildChannel.Guild) .ConfigureAwait(false); var feats = Database.Features .Find(guildChannel.GuildId); if (feats.Starboard && gld.StarDeleteIfSourceDelete) { foreach (var msg in arg1) { var message = await msg.GetOrDownloadAsync() .ConfigureAwait(false); if (Database.StarboardVotes .Any(x => x.MessageId == message.Id)) { var vote = Database.StarboardVotes .FirstOrDefault(x => x.MessageId == message.Id ); Database.StarboardVotes .RemoveRange(Database.StarboardVotes.ToList() .Where(x => x.MessageId == message.Id)); var chan = await guildChannel.Guild .GetTextChannelAsync(gld.StarboardChannel) .ConfigureAwait(false); var starMessage = await chan .GetMessageAsync(vote.StarboardMessageId) .ConfigureAwait(false); await starMessage.DeleteAsync() .ConfigureAwait(false); await Database.SaveChangesAsync() .ConfigureAwait(false); } } } } }
public static async Task <Embed> GetSummaryAsync(this IGuild guild, DiscordShardedClient client, ICommandContext context, Guild skuldguild = null) { using var Database = new SkuldDbContextFactory().CreateDbContext(); var config = Database.Configurations.Find(SkuldAppContext.ConfigurationId); var botusers = await guild.RobotMembersAsync().ConfigureAwait(false); var humanusers = await guild.HumanMembersAsync().ConfigureAwait(false); var ratio = await guild.GetBotUserRatioAsync().ConfigureAwait(false); var afkchan = await guild.GetAFKChannelAsync().ConfigureAwait(false); var owner = await guild.GetOwnerAsync().ConfigureAwait(false); var userratio = await guild.GetBotUserRatioAsync().ConfigureAwait(false); var channels = await guild.GetChannelsAsync().ConfigureAwait(false); var afktimeout = guild.AFKTimeout % 3600 / 60; var embed = new EmbedBuilder() .AddFooter(context) .WithTitle(guild.Name) .AddAuthor(context.Client) .WithColor(EmbedExtensions.RandomEmbedColor()) .AddInlineField("Users", $"Users: {humanusers.ToFormattedString()}\nBots: {botusers.ToFormattedString()}\nRatio: {ratio}%") .AddInlineField("Shard", client?.GetShardIdFor(guild)) .AddInlineField("Verification Level", guild.VerificationLevel) .AddInlineField("Voice Region", guild.VoiceRegionId) .AddInlineField("Owner", $"{owner.Mention}") .AddInlineField("Text Channels", channels.Count(x => x.GetType() == typeof(SocketTextChannel))) .AddInlineField("Voice Channels", channels.Count(x => x.GetType() == typeof(SocketVoiceChannel))) .AddInlineField("AFK Timeout", afktimeout + " minutes") .AddInlineField("Default Notifications", guild.DefaultMessageNotifications) .AddInlineField("Created", guild.CreatedAt.ToDMYString() + "\t(DD/MM/YYYY)") .AddInlineField($"Emotes [{guild.Emotes.Count}]", $" Use `{skuldguild?.Prefix ?? config.Prefix}server-emojis` to view them") .AddInlineField($"Roles [{guild.Roles.Count}]", $" Use `{skuldguild?.Prefix ?? config.Prefix}server-roles` to view them"); if (!string.IsNullOrEmpty(afkchan?.Name)) { embed.AddInlineField("AFK Channel", $"[#{afkchan.Name}]({afkchan.JumpLink()})"); } if (!string.IsNullOrEmpty(guild.IconUrl)) { embed.WithThumbnailUrl(guild.IconUrl); } return(embed.Build()); }
public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { using var Database = new SkuldDbContextFactory().CreateDbContext(); if (Database.Users.Find(context.User.Id).Flags >= DiscordUtilities.BotAdmin || (context.Client.GetApplicationInfoAsync().Result).Owner.Id == context.User.Id) { return(Task.FromResult(PreconditionResult.FromSuccess())); } else { return(Task.FromResult(PreconditionResult.FromError("Not a bot owner/developer"))); } }
public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { using var Database = new SkuldDbContextFactory().CreateDbContext(); var usr = await Database.InsertOrGetUserAsync(context.User).ConfigureAwait(false); if ((!DisabledForTesters && usr.Flags.IsBitSet(DiscordUtilities.BotTester)) || usr.Flags.IsBitSet(DiscordUtilities.BotCreator) || (!DisabledForAdmins && usr.Flags.IsBitSet(DiscordUtilities.BotAdmin))) { return(PreconditionResult.FromSuccess()); } return(PreconditionResult.FromError($"Disabled Command\nReason: \"{Reason}\"")); }
public async Task Prestige() { using var Database = new SkuldDbContextFactory().CreateDbContext(); var usr = await Database.InsertOrGetUserAsync(Context.User).ConfigureAwait(false); var nextPrestige = usr.PrestigeLevel + 1; var xp = Database.UserXp.ToList().Where(x => x.UserId == usr.Id); ulong globalLevel = 0; xp.ToList().ForEach(x => { globalLevel += x.Level; }); if (globalLevel > PrestigeRequirement * nextPrestige) { await EmbedExtensions.FromInfo("Prestige Corner", "Please respond with y/n to confirm you want to prestige\n\n**__PLEASE NOTE__**\nThis will remove **ALL** experience gotten in every server with experience enabled", Context) .QueueMessageAsync(Context) .ConfigureAwait(false); var next = await NextMessageAsync().ConfigureAwait(false); try { if (next.Content.ToBool()) { Database.UserXp.RemoveRange(Database.UserXp.ToList().Where(x => x.UserId == Context.User.Id)); await Database.SaveChangesAsync().ConfigureAwait(false); usr.PrestigeLevel = usr.PrestigeLevel.Add(1); await Database.SaveChangesAsync().ConfigureAwait(false); } } catch { DogStatsd.Increment("commands.errors", 1, 1, new[] { "err:parse-fail" }); } } else { await EmbedExtensions.FromInfo("Prestige Corner", $"You lack the amount of levels required to prestige. For your prestige level ({usr.PrestigeLevel}), it is: {PrestigeRequirement * nextPrestige}", Context) .QueueMessageAsync(Context) .ConfigureAwait(false); } }
public async Task GetServer() { using var Database = new SkuldDbContextFactory().CreateDbContext(); var dbguild = await Database.InsertOrGetGuildAsync(Context.Guild) .ConfigureAwait(false); Embed embed = await Context.Guild.GetSummaryAsync(Context.Client, Context, dbguild) .ConfigureAwait(false); await embed.QueueMessageAsync(Context).ConfigureAwait(false); }
private static async Task InsertCommandAsync(CommandInfo command, User user) { var name = command.Name ?? command.Module.Name; if (string.IsNullOrEmpty(name)) { if (command.Module.IsSubmodule) { ModuleInfo parentModule = command.Module.Parent; while (string.IsNullOrEmpty(name)) { name = parentModule.Name; if (string.IsNullOrEmpty(name) && parentModule.IsSubmodule) { parentModule = parentModule.Parent; } else if (string.IsNullOrEmpty(name) && !parentModule.IsSubmodule) { break; } } } } if (string.IsNullOrEmpty(name)) { return; } using var Database = new SkuldDbContextFactory().CreateDbContext(); var experience = Database.UserCommandUsage.FirstOrDefault(x => x.UserId == user.Id && x.Command.ToLower() == name.ToLower()); if (experience != null) { experience.Usage += 1; } else { Database.UserCommandUsage.Add(new UserCommandUsage { Command = name, UserId = user.Id, Usage = 1 }); } await Database.SaveChangesAsync().ConfigureAwait(false); }
public async Task SetMoney(IGuildUser user, ulong amount) { using var Database = new SkuldDbContextFactory().CreateDbContext(); var usr = await Database.InsertOrGetUserAsync(user).ConfigureAwait(false); usr.Money = amount; await Database.SaveChangesAsync().ConfigureAwait(false); await EmbedExtensions.FromSuccess( $"Set money of {user.Mention} to {usr.Money}", Context).QueueMessageAsync(Context) .ConfigureAwait(false); }
public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { using var Database = new SkuldDbContextFactory().CreateDbContext(); var access = await GetPermissionAsync(context, Database.Users.FirstOrDefault(x => x.Id == context.User.Id)).ConfigureAwait(false); if (access >= Level) { return(PreconditionResult.FromSuccess()); } else { return(PreconditionResult.FromError("Insufficient permissions.")); } }
public async Task GrantExp(ulong amount, [Remainder] IGuildUser user = null) { if (user == null) { user = Context.Guild.GetUser(Context.User.Id); } using var Database = new SkuldDbContextFactory().CreateDbContext(); var usr = await Database.InsertOrGetUserAsync(user).ConfigureAwait(false); await usr.GrantExperienceAsync(amount, Context, ExperienceService.DefaultAction, true).ConfigureAwait(false); await EmbedExtensions.FromSuccess($"Gave {user.Mention} {amount.ToFormattedString()}xp", Context).QueueMessageAsync(Context).ConfigureAwait(false); }
public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { if (context.Guild is null) { return(Task.FromResult(PreconditionResult.FromSuccess())); } using var Database = new SkuldDbContextFactory().CreateDbContext(); var feats = Database.Features.Find(context.Guild.Id); bool isEnabled = false; switch (Feature) { case GuildFeature.Experience: { isEnabled = feats.Experience; } break; case GuildFeature.Pinning: { isEnabled = feats.Pinning; } break; case GuildFeature.StackingRoles: { isEnabled = feats.StackingRoles; } break; case GuildFeature.Starboard: { isEnabled = feats.Starboard; } break; } if (isEnabled) { return(Task.FromResult(PreconditionResult.FromSuccess())); } else { return(Task.FromResult(PreconditionResult.FromError($"The feature: `{Feature}` is disabled, contact a server administrator to enable it"))); } }