public async Task DoDaily(SocketCommandContext context) { using (var soraContext = new SoraContext()) { // get user db data var userdb = Utility.GetOrCreateUser(context.User.Id, soraContext); // Check if he can gain again or userdb is null for some odd reason if (userdb == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Something went wrong soryy :c")); return; } if (userdb.NextDaily.CompareTo(DateTime.UtcNow) >= 0) { var timeRemaining = userdb.NextDaily.Subtract(DateTime.UtcNow.TimeOfDay).TimeOfDay; await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You can't earn anymore, please wait another {timeRemaining.Humanize(minUnit: TimeUnit.Second)}!")); return; } // add 24h cooldown userdb.NextDaily = DateTime.UtcNow.AddHours(24); // give coins userdb.Money += GAIN_COINS; // save changes await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"You gained {GAIN_COINS} Sora Coins! You can earn again in 24h.")); } }
public async Task ToggleAFK(SocketCommandContext context, string message, SoraContext soraContext) { var userDb = Utility.GetOrCreateUser(context.User.Id, soraContext); if (userDb.Afk == null) { userDb.Afk = new Afk() { IsAfk = false, UserForeignId = context.User.Id }; } if (!userDb.Afk.IsAfk) { //ADD AFK await AddAfk(context, userDb, message, false); } else { if (string.IsNullOrWhiteSpace(message)) { //REMOVE userDb.Afk.IsAfk = false; userDb.Afk.Message = ""; await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "AFK has been removed")); } else { //UPDATE await AddAfk(context, userDb, message, true); } } await soraContext.SaveChangesAsync(); }
public AllWaifus GetAllWaifus(ulong userId) { try { using (var soraContext = new SoraContext()) { var waifus = new AllWaifus(); // add up all waifus var sorted = soraContext.Waifus.OrderByDescending(x => x.Rarity); foreach (var waifu in sorted) { waifus.Waifus.Add(waifu); } // send all waifus return(waifus); } } catch (Exception e) { Console.WriteLine(e); } return(null); }
public async Task UserInfo([Summary("User to display info of")] SocketUser userT = null) { SocketGuildUser user = (SocketGuildUser)(userT ?? Context.User); using (var soraContext = new SoraContext()) { var eb = new EmbedBuilder() { Color = Utility.BlueInfoEmbed, ThumbnailUrl = user.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Title = $"{Utility.SuccessLevelEmoji[3]} {user.Username}", Description = $"Joined Discord on {user.CreatedAt.ToString("dd/MM/yyyy")}. That is {(int)(DateTime.Now.Subtract(user.CreatedAt.DateTime).TotalDays)} days ago!", Footer = new EmbedFooterBuilder() { IconUrl = Context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Text = $"Requested by {Utility.GiveUsernameDiscrimComb(Context.User)} | User ID: {user.Id}" } }; eb.AddField(x => { x.IsInline = true; x.Name = $"Status"; x.Value = user.Status.Humanize().Transform(To.LowerCase, To.TitleCase); }); eb.AddField(x => { x.IsInline = true; x.Name = $"Game"; x.Value = $"{(user.Game.HasValue ? user.Game.Value.Name : "*none*")}"; }); eb.AddField(x => { x.IsInline = true; x.Name = $"Nickname"; x.Value = $"{(user.Nickname == null ? "*none*" : $"{user.Nickname}")}"; });
public async Task RemoveBg(SocketCommandContext context) { using (var soraContext = new SoraContext()) { var userDb = Utility.GetOrCreateUser(context.User.Id, soraContext); if (!userDb.HasBg) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You don't even have a BG set...")); return; } userDb.HasBg = false; await soraContext.SaveChangesAsync(); } if (File.Exists($"ProfileData/{context.User.Id}BGF.png")) { File.Delete($"ProfileData/{context.User.Id}BGF.png"); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully delete the BG!")); }
public async Task SetPublic(SocketCommandContext context, string url) { using (var soraContext = new SoraContext()) { var userDb = Utility.OnlyGetUser(context.User.Id, soraContext); if (userDb == null || userDb.ShareCentrals.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You have no playlists")); return; } var shareResult = userDb.ShareCentrals.FirstOrDefault(x => x.ShareLink == url); if (shareResult == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "No playlist found with that URL!")); return; } if (!shareResult.IsPrivate) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Playlist already is set to PUBLIC")); return; } shareResult.IsPrivate = false; await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Playlist is now PUBLIC")); } }
public async Task RemovePlaylist(SocketCommandContext context, string url) { using (var soraContext = new SoraContext()) { var userDb = Utility.OnlyGetUser(context.User.Id, soraContext); if (userDb == null || userDb.ShareCentrals.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You have no shared playlists!")); return; } var result = userDb.ShareCentrals.FirstOrDefault(x => x.ShareLink == url); if (result == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "URL not found in your shared playlists")); return; } userDb.ShareCentrals.Remove(result); var votes = soraContext.Votings.Where(x => x.ShareLink == result.ShareLink).ToList(); foreach (var voting in votes) { soraContext.Votings.Remove(voting); } await soraContext.SaveChangesAsync(); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully removed playlist")); }
public async Task SetFavWaifu([Remainder] string name) { int waifuId = 0; using (var soraContext = new SoraContext()) { name = name.Replace("\"", ""); var waifu = soraContext.Waifus.FirstOrDefault(x => x.Name.Equals(name.Trim(), StringComparison.OrdinalIgnoreCase)); if (waifu == null) { await ReplyAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "That waifu doesn't exist." )); return; } waifuId = waifu.Id; } await _waifuService.SetFavoriteWaifu(Context, waifuId); }
public async Task ListSars(SocketCommandContext context) { using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); int roleCount = guildDb.SelfAssignableRoles.Count; if (roleCount == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Guild has no self-assignable roles!")); return; } if (roleCount < 24) { var eb = new EmbedBuilder() { Color = Utility.PurpleEmbed, Title = $"Self-Assignable roles in {context.Guild.Name}", ThumbnailUrl = context.Guild.IconUrl ?? Utility.StandardDiscordAvatar, Footer = Utility.RequestedBy(context.User) }; List <Role> roleList = new List <Role>(guildDb.SelfAssignableRoles); foreach (var role in roleList) { //check if role still exists otherwise remove it var roleInfo = context.Guild.GetRole(role.RoleId); if (roleInfo == null) { guildDb.SelfAssignableRoles.Remove(role); continue; } eb.AddField(x => { x.IsInline = true; x.Name = roleInfo.Name; x.Value = $"Cost: {role.Cost}{(role.CanExpire ? $"\nDuration: {role.Duration.Humanize(2, maxUnit: TimeUnit.Day, minUnit: TimeUnit.Second, countEmptyUnits:true)}" : "")}"; }); //eb.Description += $"• {roleInfo.Name}\n"; } await context.Channel.SendMessageAsync("", embed : eb); } else { List <Role> roleList = new List <Role>(guildDb.SelfAssignableRoles); List <string> sars = new List <string>(); int pageAmount = (int)Math.Ceiling(roleCount / 7.0); int addToJ = 0; int amountLeft = roleCount; for (int i = 0; i < pageAmount; i++) { string addToList = ""; for (int j = 0; j < (amountLeft > 7 ? 7 : amountLeft); j++) { var role = roleList[j + addToJ]; var roleInfo = context.Guild.GetRole(role.RoleId); if (roleInfo == null) { guildDb.SelfAssignableRoles.Remove(role); continue; } addToList += $"**{roleInfo.Name}**\nCost: {role.Cost}{(role.CanExpire ? $" \t \tDuration: {role.Duration.Humanize(2, maxUnit: TimeUnit.Day, minUnit: TimeUnit.Second, countEmptyUnits:true)} days" : "")}"; } sars.Add(addToList); amountLeft -= 7; addToJ += 7; } var pmsg = new PaginatedMessage() { Author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = context.User.Username }, Color = Utility.PurpleEmbed, Title = $"Self-Assignable roles in {context.Guild.Name}", Options = new PaginatedAppearanceOptions() { DisplayInformationIcon = false, Timeout = TimeSpan.FromSeconds(60), InfoTimeout = TimeSpan.FromSeconds(60) }, Content = "Only the invoker may switch pages, ⏹ to stop the pagination", Pages = sars }; Criteria <SocketReaction> criteria = new Criteria <SocketReaction>(); criteria.AddCriterion(new EnsureReactionFromSourceUserCriterionMod()); await _interactive.SendPaginatedMessageAsync(context, pmsg, criteria); } await soraContext.SaveChangesAsync(); } }
private async void CheckExpiringRoles(Object stateInfo) { try { using (var soraContext = new SoraContext()) { var roles = new List <ExpiringRole>(); roles = soraContext.ExpiringRoles.ToList(); foreach (var role in roles) { // get guild var guild = _client.GetGuild(role.GuildForeignId); if (guild == null) { continue; } // get user var user = guild.GetUser(role.UserForeignId); // if user isnt in guild anymore remove entry if (user == null) { soraContext.ExpiringRoles.Remove(role); continue; } // get role var r = guild.GetRole(role.RoleForeignId); // remove if role doesnt exist anymore if (r == null) { soraContext.ExpiringRoles.Remove(role); continue; } // check if user still has role if (user.Roles.All(x => x.Id != role.RoleForeignId)) { // user doesnt have role anymore. remove soraContext.ExpiringRoles.Remove(role); continue; } if (role.ExpiresAt.CompareTo(DateTime.UtcNow) <= 0) { // otherwise remove role from him and entry // ratelimit is super strict here so what we do is try it, // if it throws an exception we wait 2 seconds and try again. Hopefully that works. // otherwise we run again and retry. try { await user.RemoveRoleAsync(r); soraContext.ExpiringRoles.Remove(role); } catch (Exception e) { await Task.Delay(3000); // Role ratelimit is quite severe. so after removing one role we'll just wait since this is no pushing task. await user.RemoveRoleAsync(r); soraContext.ExpiringRoles.Remove(role); } } } await soraContext.SaveChangesAsync(); } ChangeToClosestInterval(); } catch (Exception e) { Console.WriteLine(e); } }
public async Task IAmNotSar(SocketCommandContext context, string roleName) { var sora = context.Guild.CurrentUser; //Check if sora can create a role if (!sora.GuildPermissions.Has(GuildPermission.ManageRoles)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Sora doesn't have ManageRoles Permission. Please notify an admin!")); return; } //check if the user has the role var user = (SocketGuildUser)context.User; var role = user.Roles.FirstOrDefault(x => x.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase)); if (role == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You don't carry this role!")); return; } using (SoraContext soraContext = new SoraContext()) { //check if the role is self assignable var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); var roleDb = guildDb.SelfAssignableRoles.FirstOrDefault(x => x.RoleId == role.Id); if (roleDb == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "This role is not self-assignable!")); return; } //user carries role and IS self assignable // check if it had a duration if (roleDb.CanExpire) { // remove entry in that list if it exists var expireDb = soraContext.ExpiringRoles.FirstOrDefault(x => x.RoleForeignId == role.Id && x.UserForeignId == user.Id); if (expireDb != null) { soraContext.ExpiringRoles.Remove(expireDb); await soraContext.SaveChangesAsync(); ChangeToClosestInterval(); } } await user.RemoveRoleAsync(role); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully removed {role.Name} from your roles!")); }
public async Task AddSarToList(SocketCommandContext context, string roleName, bool canExpire = false, int cost = 0, TimeSpan expireAt = new TimeSpan()) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return; } var sora = context.Guild.CurrentUser; //Try to find role IRole role = context.Guild.Roles.FirstOrDefault(x => x.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase)); bool wasCreated = false; //Role wasn't found if (role == null) { //Check if sora can create a role if (!sora.GuildPermissions.Has(GuildPermission.ManageRoles)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "The specified role was not found and Sora doesn't have ManageRoles permissions to create it!")); return; } //he has the perms so he can create the role role = await context.Guild.CreateRoleAsync(roleName, GuildPermissions.None); wasCreated = true; } else { //check if the role found is ABOVE sora if so.. quit. (on life) var soraHighestRole = sora.Roles.OrderByDescending(x => x.Position).FirstOrDefault(); //Sora is below in the hirarchy if (soraHighestRole.Position < role.Position) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "I cannot assign roles that are above me in the role hirachy!") .WithDescription("If this is not the case, open the server settings and move a couple roles around since discord doesn't refresh the position unless they are moved.")); return; } } //role was either found or created by sora.. using (SoraContext soraContext = new SoraContext()) { //check if it already exists var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); if (guildDb.SelfAssignableRoles.Count > 0 && guildDb.SelfAssignableRoles.Any(x => x.RoleId == role.Id)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "This role is already self assignable!")); return; } //Add it to the list! guildDb.SelfAssignableRoles.Add(new Role() { CanExpire = canExpire, Cost = cost, Duration = expireAt, GuildForeignId = context.Guild.Id, RoleId = role.Id }); //save DB await soraContext.SaveChangesAsync(); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully{(wasCreated ? " created and" : "")} added {roleName} to the list of self-assignable roles!")); }
public async Task SearchPlaylistByTags(SocketCommandContext context, string tags) { string[] seperatedTags; if (tags.IndexOf(";", StringComparison.Ordinal) < 1) { seperatedTags = new[] { tags }; } else { seperatedTags = tags.Split(";"); } using (var soraContext = new SoraContext()) { List <SearchStruct> searchResult = new List <SearchStruct>(); foreach (var playlist in soraContext.ShareCentrals.Where(x => x.IsPrivate == false)) { int matches = 0; string[] playlistTags = playlist.Tags.Split(";"); foreach (var tag in seperatedTags) { foreach (var playlistTag in playlistTags) { if (tag.Trim().Equals(playlistTag.Trim(), StringComparison.OrdinalIgnoreCase)) { matches++; } } } if (matches > 0) { searchResult.Add(new SearchStruct() { Matches = matches, SharedPlaylist = playlist }); } } if (searchResult.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Nothing found with entered tags")); return; } var orderedList = searchResult.OrderByDescending(x => x.Matches).ThenByDescending(x => (x.SharedPlaylist.Upvotes - x.SharedPlaylist.Downvotes)).ToList(); List <string> playlistsString = new List <string>(); int pageAmount = (int)Math.Ceiling(orderedList.Count / 7.0); int addToJ = 0; int amountLeft = orderedList.Count; for (int i = 0; i < pageAmount; i++) { string addToList = ""; for (int j = 0; j < (amountLeft > 7 ? 7 : amountLeft); j++) { var sharedPlaylist = orderedList[j + addToJ].SharedPlaylist; addToList += $"**[{sharedPlaylist.Titel}]({sharedPlaylist.ShareLink})**\nVotes: {sharedPlaylist.Upvotes} / {sharedPlaylist.Downvotes} \tTags: {sharedPlaylist.Tags.Replace(";", " - ")}\n\n"; } playlistsString.Add(addToList); amountLeft -= 7; addToJ += 7; } if (pageAmount > 1) { var pmsg = new PaginatedMessage() { Author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = context.User.Username }, Color = Utility.PurpleEmbed, Title = $"🔍 Search Results", Options = new PaginatedAppearanceOptions() { DisplayInformationIcon = false, Timeout = TimeSpan.FromSeconds(30), InfoTimeout = TimeSpan.FromSeconds(30) }, Content = "Only the invoker may switch pages, ⏹ to stop the pagination", Pages = playlistsString }; Criteria <SocketReaction> criteria = new Criteria <SocketReaction>(); criteria.AddCriterion(new EnsureReactionFromSourceUserCriterionMod()); await _interactive.SendPaginatedMessageAsync(context, pmsg, criteria); } else { var eb = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = context.User.Username }, Color = Utility.PurpleEmbed, Title = $"Search Results", Description = playlistsString[0], Footer = new EmbedFooterBuilder() { Text = "Page 1/1" } }; await context.Channel.SendMessageAsync("", embed : eb); } } }
/// <summary> /// Tries to get a GuildUser. If it cannot find one it creates one and adds it to the guildUser Dbset to be tracked. /// This does NOT save tho! /// If it cannot find a user it will CREATE AND SAVE a guild object bcs of the foreign key constraint! /// </summary> public static async Task <GuildUser> GetOrCreateGuildUser(ulong guildId, ulong userId, SoraContext context) { var guildUser = await context.GuildUsers .FirstOrDefaultAsync(x => x.UserId == userId && x.GuildId == guildId).ConfigureAwait(false); if (guildUser != null) { return(guildUser); } // Create a user and return him // Because of the foreign key constraints we have to make sure a guild exists and a user // This will create the guild await GetOrSetAndGetGuildNoSave(guildId, context).ConfigureAwait(false); await context.Users.GetOrCreateUserNoSaveAsync(userId).ConfigureAwait(false); await context.SaveChangesAsync().ConfigureAwait(false); // Now we add the user guildUser = new GuildUser(userId, guildId, 0); context.GuildUsers.Add(guildUser); return(guildUser); }
public async Task RemoveReminder(SocketCommandContext context) { using (var _soraContext = new SoraContext()) { var userDb = Utility.OnlyGetUser(context.User.Id, _soraContext); if (userDb == null || userDb.Reminders.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You have no reminders!")); return; } var eb = new EmbedBuilder() { Color = Utility.PurpleEmbed, Title = "Enter index of reminder to remove", ThumbnailUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar }; var orderedReminders = _soraContext.Reminders.Where(x => x.UserForeignId == context.User.Id).ToList(); for (int i = 0; i < (orderedReminders.Count > 24 ? 24 : orderedReminders.Count); i++) { eb.AddField(x => { x.Name = $"Reminder #{i + 1} in {ConvertTime(orderedReminders[i].Time.Subtract(DateTime.UtcNow).TotalSeconds)}"; x.IsInline = false; x.Value = $"{(orderedReminders[i].Message.Length > 80 ? orderedReminders[i].Message.Remove(80) + "..." : orderedReminders[i].Message)}"; }); } var msg = await context.Channel.SendMessageAsync("", embed : eb); //var response = await _interactive.WaitForMessage(context.User, context.Channel, TimeSpan.FromSeconds(45)); var response = await _interactive.NextMessageAsync(context, true, true, TimeSpan.FromSeconds(45));//TODO test if this listens only to source user and source channel await msg.DeleteAsync(); if (response == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{Utility.GiveUsernameDiscrimComb(context.User)} didn't reply in time :<")); return; } int index = 0; if (!Int32.TryParse(response.Content, out index)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Only add the Index!")); return; } if (index > (orderedReminders.Count + 1) || index < 1) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Invalid Number")); return; } index -= 1; _soraContext.Reminders.Remove(orderedReminders[index]); await _soraContext.SaveChangesAsync(); ChangeToClosestInterval(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully removed reminder")); } }
public async Task Marry(SocketCommandContext context, SocketUser user) { //Check if its urself if (user.Id == context.User.Id) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You can't and shouldn't marry yourself ;_;")); return; } using (var soraContext = new SoraContext()) { var requestorDb = Utility.GetOrCreateUser(context.User.Id, soraContext); var askedDb = Utility.GetOrCreateUser(user.Id, soraContext); int allowedMarriagesRequestor = ((int)(Math.Floor((double)(ExpService.CalculateLevel(requestorDb.Exp) / 10)))) + 1; int allowedMarriagesAsked = ((int)(Math.Floor((double)(ExpService.CalculateLevel(askedDb.Exp) / 10)))) + 1; //check both limits if (requestorDb.Marriages.Count >= allowedMarriagesRequestor) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{Utility.GiveUsernameDiscrimComb(context.User)}, you already reached your marriage limit. Level up to increase it")); return; } if (askedDb.Marriages.Count >= allowedMarriagesAsked) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{Utility.GiveUsernameDiscrimComb(user)} already reached their marriage limit. They must level up to increase the limit")); //TODO this sounds like shit. change it return; } //Check for duplicate if (requestorDb.Marriages.Any(x => x.PartnerId == user.Id) || askedDb.Marriages.Any(x => x.PartnerId == context.User.Id)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You cannot marry someone twice!")); return; } //Proceed to ask for marriage var msg = await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.PurpleEmbed, Utility.SuccessLevelEmoji[4], $"{Utility.GiveUsernameDiscrimComb(user)}, do you want to marry {Utility.GiveUsernameDiscrimComb(context.User)}? 💍")); Criteria <SocketMessage> criteria = new Criteria <SocketMessage>(); criteria.AddCriterion(new EnsureFromUserInChannel(user.Id, context.Channel.Id)); var response = await _interactive.NextMessageAsync(context, criteria, TimeSpan.FromSeconds(45)); if (response == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{Utility.GiveUsernameDiscrimComb(user)} didn't answer in time >.<")); return; } if ((!response.Content.Contains(" yes ", StringComparison.OrdinalIgnoreCase) && !response.Content.Contains(" yes,", StringComparison.OrdinalIgnoreCase) && !response.Content.Contains("yes ", StringComparison.OrdinalIgnoreCase) && !response.Content.Contains("yes,", StringComparison.OrdinalIgnoreCase)) && !response.Content.Equals("yes", StringComparison.OrdinalIgnoreCase)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{Utility.GiveUsernameDiscrimComb(user)} didn't answer with a yes ˚‧º·(˚ ˃̣̣̥᷄⌓˂̣̣̥᷅ )‧º·˚")); return; } //Answer contains a yes requestorDb.Marriages.Add(new Marriage() { PartnerId = user.Id, Since = DateTime.UtcNow }); //_soraContext.SaveChangesThreadSafe(); askedDb.Marriages.Add(new Marriage() { PartnerId = context.User.Id, Since = DateTime.UtcNow }); await soraContext.SaveChangesAsync(); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.PurpleEmbed, Utility.SuccessLevelEmoji[4], $"You are now married 💑").WithImageUrl("https://media.giphy.com/media/iQ5rGja9wWB9K/giphy.gif")); }
public async Task CheckAffinity(SocketUser user, SocketCommandContext context, SoraContext soraContext) { //FindUserMentioned var dbUser = Utility.OnlyGetUser(user.Id, soraContext); if (dbUser == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{Utility.GiveUsernameDiscrimComb(user)} has no Interactions yet!")); return; } var eb = new EmbedBuilder() { Color = Utility.PurpleEmbed, Footer = new EmbedFooterBuilder() { Text = $"Requested by {context.User.Username}#{context.User.Discriminator}", IconUrl = (context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar) }, Title = $"Affinity stats of {user.Username}#{user.Discriminator}", ThumbnailUrl = (user.GetAvatarUrl() ?? Utility.StandardDiscordAvatar), Description = "Received Interactions / Given Interactions" }; eb.AddField((x) => { x.IsInline = true; x.Name = $"Pats"; x.Value = $"{dbUser.Interactions.Pats}/{dbUser.Interactions.PatsGiven}"; }); eb.AddField((x) => { x.IsInline = true; x.Name = $"High5"; x.Value = $"{dbUser.Interactions.High5}/{dbUser.Interactions.High5Given}"; }); eb.AddField((x) => { x.IsInline = true; x.Name = $"Hugs"; x.Value = $"{dbUser.Interactions.Hugs}/{dbUser.Interactions.HugsGiven}"; }); eb.AddField((x) => { x.IsInline = true; x.Name = $"Kisses"; x.Value = $"{dbUser.Interactions.Kisses}/{dbUser.Interactions.KissesGiven}"; }); eb.AddField((x) => { x.IsInline = true; x.Name = $"Pokes"; x.Value = $"{dbUser.Interactions.Pokes}/{dbUser.Interactions.PokesGiven}"; }); eb.AddField((x) => { x.IsInline = true; x.Name = $"Slaps"; x.Value = $"{dbUser.Interactions.Slaps}/{dbUser.Interactions.SlapsGiven}"; }); eb.AddField((x) => { x.IsInline = true; x.Name = $"Punches"; x.Value = $"{dbUser.Interactions.Punches}/{dbUser.Interactions.PunchesGiven}"; }); eb.AddField((x) => { x.IsInline = true; x.Name = $"Affinity"; double aff = Utility.CalculateAffinity(dbUser.Interactions); string icon = MySwitch.First(sw => sw.Key((int)Math.Round(aff))).Value; x.Value = $"{aff}/100 {icon}"; }); await context.Channel.SendMessageAsync("", false, eb); }
public async Task SharePlaylist(SocketCommandContext context, string shareUrl, string title, string tags, bool isPrivate) { using (var soraContext = new SoraContext()) { var userDb = Utility.OnlyGetUser(context.User.Id, soraContext); if (userDb == null || ExpService.CalculateLevel(userDb.Exp) < MIN_LEVEL) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You need to be at least lvl {MIN_LEVEL} to share playlists!")); return; } if (await CanAddNewPlaylist(context, userDb) == false) { return; } if (!shareUrl.StartsWith("https://hastebin.com/")) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "The link must be a valid hastebin link!")); return; } if (!shareUrl.EndsWith(".sora") && !shareUrl.EndsWith(".fredboat")) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Must be an originaly exported sora or fredboat playlist!") .WithDescription( $"Use `{Utility.GetGuildPrefix(context.Guild, soraContext)}export` when you have a Queue! This is to minimize errors.")); return; } if (shareUrl.EndsWith(".fredboat")) { shareUrl = shareUrl.Replace(".fredboat", ".sora"); } if (soraContext.ShareCentrals.Any(x => x.ShareLink == shareUrl)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Playlist already exists!")); return; } string[] seperatedTags; if (tags.IndexOf(";", StringComparison.Ordinal) < 1) { seperatedTags = new[] { tags }; } else { seperatedTags = tags.Split(";"); } List <string> betterTags = new List <string>(); foreach (var tag in seperatedTags) { string finalTag = tag; if (finalTag.Contains(";")) { finalTag = finalTag.Replace(";", ""); } if (!string.IsNullOrWhiteSpace(finalTag)) { betterTags.Add(finalTag.Trim()); } } if (betterTags.Count < 1) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Add at least one Tag!").WithDescription("Tags must be added like this: `trap;edm;chill music;other`")); return; } if (betterTags.Count > 10) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Please dont exceed 10 tags!")); return; } string joinedTags = String.Join(";", betterTags); var eb = new EmbedBuilder() { Color = Utility.BlueInfoEmbed, Title = $"{Utility.SuccessLevelEmoji[3]} Are you sure you want share this? y/n", Description = $"{shareUrl}\n" + $"You can change the Title and Tags afterwards but never the playlist link!", Author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = Utility.GiveUsernameDiscrimComb(context.User) } }; eb.AddField(x => { x.IsInline = false; x.Name = "Title"; x.Value = title; }); eb.AddField(x => { x.IsInline = true; x.Name = "Tags"; x.Value = joinedTags.Replace(";", " - "); }); eb.AddField(x => { x.IsInline = true; x.Name = "Is Private?"; x.Value = $"{(isPrivate ? "Yes" : "No")}"; }); var msg = await context.Channel.SendMessageAsync("", embed : eb); var response = await _interactive.NextMessageAsync(context, true, true, TimeSpan.FromSeconds(45)); await msg.DeleteAsync(); if (response == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Didn't answer in time ;_;")); return; } if (response.Content.Equals("y", StringComparison.OrdinalIgnoreCase) || response.Content.Equals("yes", StringComparison.OrdinalIgnoreCase)) { userDb.ShareCentrals.Add(new ShareCentral() { CreatorId = context.User.Id, Downvotes = 0, Upvotes = 0, ShareLink = shareUrl, Titel = title, IsPrivate = isPrivate, Tags = joinedTags }); await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully {(isPrivate ? "saved" : "shared")} playlist (ノ◕ヮ◕)ノ*:・゚✧")); } else { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Didn't answer with y or yes! Discarded changes")); } } }
public async Task UpdateEntry(SocketCommandContext context, string shareUrl, string title, string tags) { using (var soraContext = new SoraContext()) { var userDb = Utility.OnlyGetUser(context.User.Id, soraContext); if (userDb == null || userDb.ShareCentrals.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You have no playlists")); return; } var shareResult = userDb.ShareCentrals.FirstOrDefault(x => x.ShareLink == shareUrl); if (shareResult == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "No playlist found with that URL!")); return; } string[] seperatedTags; if (tags.IndexOf(";", StringComparison.Ordinal) < 1) { seperatedTags = new[] { tags }; } else { seperatedTags = tags.Split(";"); } List <string> betterTags = new List <string>(); foreach (var tag in seperatedTags) { string finalTag = tag; if (finalTag.Contains(";")) { finalTag = finalTag.Replace(";", ""); } if (!string.IsNullOrWhiteSpace(finalTag)) { betterTags.Add(finalTag.Trim()); } } if (betterTags.Count < 1) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Add at least one Tag!").WithDescription("Tags must be added like this: `trap;edm;chill music;other`")); return; } if (betterTags.Count > 10) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Please dont exceed 10 tags!")); return; } string joinedTags = String.Join(";", betterTags); var eb = new EmbedBuilder() { Color = Utility.BlueInfoEmbed, Title = $"{Utility.SuccessLevelEmoji[3]} Are you sure you want Update this? y/n", Description = $"{shareUrl}", Author = new EmbedAuthorBuilder() { IconUrl = context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = Utility.GiveUsernameDiscrimComb(context.User) } }; eb.AddField(x => { x.IsInline = false; x.Name = "Title"; x.Value = title; }); eb.AddField(x => { x.IsInline = true; x.Name = "Tags"; x.Value = joinedTags.Replace(";", " - "); }); var msg = await context.Channel.SendMessageAsync("", embed : eb); var response = await _interactive.NextMessageAsync(context, true, true, TimeSpan.FromSeconds(45)); await msg.DeleteAsync(); if (response == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Didn't answer in time ;_;")); return; } if (response.Content.Equals("y", StringComparison.OrdinalIgnoreCase) || response.Content.Equals("yes", StringComparison.OrdinalIgnoreCase)) { shareResult.Tags = joinedTags; shareResult.Titel = title; await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully updated playlist (ノ◕ヮ◕)ノ*:・゚✧")); } else { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Didn't answer with y or yes! Discarded changes")); } } }
public async Task IAmSar(SocketCommandContext context, string roleName) { var sora = context.Guild.CurrentUser; //Check if sora can create a role if (!sora.GuildPermissions.Has(GuildPermission.ManageRoles)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Sora doesn't have ManageRoles Permission. Please notify an admin!")); return; } //check if role exists var role = context.Guild.Roles.FirstOrDefault(x => x.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase)); if (role == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "This role does not exist!")); return; } //Check if he already has the role var user = (SocketGuildUser)context.User; if (user.Roles.Any(x => x.Id == role.Id)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You already have this role!")); return; } using (SoraContext soraContext = new SoraContext()) { //check if the role is self assignable var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); var roleDb = guildDb.SelfAssignableRoles.FirstOrDefault(x => x.RoleId == role.Id); if (roleDb == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "This role is not self-assignable!")); return; } // role exists and IS self assignable // check if it costs. if (roleDb.Cost > 0) { // check if user has enough money. var userDb = Utility.GetOrCreateUser(user.Id, soraContext); if (userDb.Money < roleDb.Cost) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You don't have enough Sora Coins for this role.")); return; } // He has enough SC to buy // Get owner db var ownerDb = Utility.GetOrCreateUser(context.Guild.OwnerId, soraContext); userDb.Money -= roleDb.Cost; // only send 50% of it to the owner. the rest is tax to remove money from the economy. ownerDb.Money += (int)Math.Floor(roleDb.Cost / 2.0); // check if duration if (roleDb.CanExpire) { // add role to list of expiring roles. soraContext.ExpiringRoles.Add(new ExpiringRole() { RoleForeignId = role.Id, ExpiresAt = DateTime.UtcNow.Add(roleDb.Duration), GuildForeignId = context.Guild.Id, UserForeignId = user.Id }); Console.WriteLine($"EXPIRES AT: {DateTime.UtcNow.Add(roleDb.Duration)}"); } await soraContext.SaveChangesAsync(); ChangeToClosestInterval(); } await user.AddRoleAsync(role); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully added {role.Name} to your roles!")); }
public async Task QuickSellWaifus(SocketCommandContext context, int waifuId, int amount) { using (var soraContext = new SoraContext()) { var userdb = Utility.OnlyGetUser(context.User.Id, soraContext); if (userdb == null || userdb.UserWaifus.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You have no waifus to sell! Open some WaifuBoxes!" )); return; } var selected = userdb.UserWaifus.FirstOrDefault(x => x.WaifuId == waifuId); if (selected == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Either this waifu doesn't exist or you don't own it!" )); return; } if (selected.Count < amount) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You don't have enough of this Waifu. Sell less!" )); return; } selected.Count -= amount; var waifu = soraContext.Waifus.FirstOrDefault(x => x.Id == waifuId); int cash = GetWaifuQuickSellCost(waifu?.Rarity ?? 0) * amount; userdb.Money += cash; bool fav = false; if (selected.Count == 0) { fav = RemoveWaifuFromUser(userdb, selected); } await soraContext.SaveChangesAsync(); var eb = Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"You successfully sold {amount} for {cash} SC." ); if (fav) { eb.WithDescription("You sold your Favorite Waifu. Thus it has been removed from your profile."); } await context.Channel.SendMessageAsync("", embed : eb); } }
public async Task ListAllCasesWithUser(SocketCommandContext context, SocketGuildUser user) { var sora = context.Guild.CurrentUser; //Check if user has at least some perms if (await CheckPermissions(context, Case.Warning, sora, user) == false) { return; } using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); //search for cases with him var userCases = guildDb.Cases.Where(x => x.UserId == user.Id)?.ToList(); if (userCases == null || userCases.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "User has no logged cases!")); return; } var eb = new EmbedBuilder() { Color = Utility.PurpleEmbed, Footer = Utility.RequestedBy(context.User), ThumbnailUrl = user.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Title = $"Cases of {Utility.GiveUsernameDiscrimComb(user)}" }; int count = 0; foreach (var userCase in userCases) { if (count >= 22) { eb.AddField(x => { x.IsInline = false; x.Name = "Can't show more"; x.Value = "Honestly... You should ban him..."; }); break; } string title = ""; switch (userCase.Type) { case Case.Ban: title = $"Case #{userCase.CaseNr} | Ban 🔨"; break; case Case.Kick: title = $"Case #{userCase.CaseNr} | Kick 👢"; break; case Case.Warning: title = $"Case #{userCase.CaseNr} | Warning #{userCase.WarnNr} ⚠"; break; default: title = "Undefined"; break; } var mod = context.Guild.GetUser(userCase.ModId); eb.AddField(x => { x.IsInline = false; x.Name = title; x.Value = $"{(string.IsNullOrWhiteSpace(userCase.Reason) ? "Undefined" : userCase.Reason)}\n" + $"*by {(mod == null ? "Undefined" : $"{Utility.GiveUsernameDiscrimComb(mod)}")}*"; }); } await context.Channel.SendMessageAsync("", embed : eb); } }
public async Task MakeTradeOffer(SocketCommandContext context, SocketGuildUser other, int wantId, int offerId) { using (var soraContext = new SoraContext()) { // check if they have ANY waifus at all var userdb = Utility.OnlyGetUser(context.User.Id, soraContext); if (userdb == null || userdb.UserWaifus.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You have no waifus to trade! Open some WaifuBoxes!" )); return; } var otherdb = Utility.OnlyGetUser(other.Id, soraContext); if (otherdb == null || otherdb.UserWaifus.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{other.Username} has no waifus to trade!" )); return; } // check if both have the offered waifus. // first other var otherWaifu = otherdb.UserWaifus.FirstOrDefault(x => x.WaifuId == wantId); if (otherWaifu == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{other.Username} doesn't have that waifu!" )); return; } // now us var userWaifu = userdb.UserWaifus.FirstOrDefault(x => x.WaifuId == offerId); if (userWaifu == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You don't have that waifu to offer!" )); return; } // now ask for the trade. var otherW = soraContext.Waifus.FirstOrDefault(x => x.Id == wantId); var userW = soraContext.Waifus.FirstOrDefault(x => x.Id == offerId); var eb = new EmbedBuilder() { Title = "Waifu Trade Request", Description = $"{context.User.Username} has requested to trade with you.", Color = Utility.PurpleEmbed, Footer = Utility.RequestedBy(context.User), ImageUrl = userW.ImageUrl }; eb.AddField(x => { x.IsInline = true; x.Name = "User offers"; x.Value = $"{userW.Name}\n{GetRarityString(userW.Rarity)}\n*ID: {userW.Id}*"; }); eb.AddField(x => { x.IsInline = true; x.Name = "User Wants"; x.Value = $"{otherW.Name}\n{GetRarityString(otherW.Rarity)}\n*ID: {otherW.Id}*"; }); eb.AddField(x => { x.IsInline = false; x.Name = "Accept?"; x.Value = "You can accept this trade by writing `y` and decline by writing anything else."; }); await context.Channel.SendMessageAsync("", embed : eb); Criteria <SocketMessage> criteria = new Criteria <SocketMessage>(); criteria.AddCriterion(new EnsureFromUserInChannel(other.Id, context.Channel.Id)); var response = await _interactive.NextMessageAsync(context, criteria, TimeSpan.FromSeconds(45)); if (response == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{other.Username} didn't answer in time >.<")); return; } if (!response.Content.Equals("y", StringComparison.OrdinalIgnoreCase)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{other.Username} declined the trade offer!")); return; } // accepted offer // add waifu GiveWaifuToId(userdb.UserId, otherW.Id, userdb); GiveWaifuToId(other.Id, userW.Id, otherdb); // remove waifu userWaifu.Count--; bool fav1 = false; bool fav2 = false; if (userWaifu.Count == 0) { fav1 = RemoveWaifuFromUser(userdb, userWaifu); } otherWaifu.Count--; if (otherWaifu.Count == 0) { fav2 = RemoveWaifuFromUser(otherdb, otherWaifu); } // completed trade await soraContext.SaveChangesAsync(); string desc = ""; if (fav1) { desc += $"{context.User.Username}, you traded away your favorite Waifu. It has been removed from your profile.\n"; } if (fav2) { desc += $"{other.Username}, you traded away your favorite Waifu. It has been removed from your profile."; } var eb2 = Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully traded {userW.Name} for {otherW.Name}." ); if (!string.IsNullOrWhiteSpace(desc)) { eb2.WithDescription(desc); } await context.Channel.SendMessageAsync("", embed : eb2); } }
public async Task VotePlaylist(SocketCommandContext context, string url, bool vote) { using (var soraContext = new SoraContext()) { var userDb = Utility.OnlyGetUser(context.User.Id, soraContext); if (userDb == null || ExpService.CalculateLevel(userDb.Exp) < MIN_LEVEL) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You need to be at least lvl {MIN_LEVEL} to vote on playlists!")); return; } var playlistDb = soraContext.ShareCentrals.FirstOrDefault(x => x.ShareLink == url); if (playlistDb == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "There is no shared playlist with that Url!")); return; } //First check if it was ever voted on var voteDb = soraContext.Votings.FirstOrDefault(x => x.ShareLink == url && x.VoterId == context.User.Id); if (voteDb == null) { userDb.Votings.Add(new Voting() { ShareLink = playlistDb.ShareLink, UpOrDown = vote, VoterId = context.User.Id }); if (vote) //UPVOTED { playlistDb.Upvotes++; await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully UPVOTED playlist")); } else //DOWNVOTED { playlistDb.Downvotes++; await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully DOWNVOTED playlist")); } await soraContext.SaveChangesAsync(); } else { if (voteDb.UpOrDown == vote) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You already voted this playlist with this vote! You can change your vote though!")); return; } voteDb.UpOrDown = vote; if (vote) //UPVOTE { playlistDb.Downvotes--; playlistDb.Upvotes++; await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully updated vote to UPVOTED!")); } else//DOWNVOTE { playlistDb.Downvotes++; playlistDb.Upvotes--; await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully updated vote to DOWNVOTED!")); } await soraContext.SaveChangesAsync(); } } }
public async Task RemoveWarnings(SocketCommandContext context, SocketGuildUser user, int warnNr, bool all) { var sora = context.Guild.CurrentUser; //Check if user has at least some perms if (await CheckPermissions(context, Case.Warning, sora, user) == false) { return; } using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); //make sure punish logs channel is still available var channel = context.Guild.GetTextChannel(guildDb.PunishLogsId); if (channel == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Can't remove warnings without a punishlogs channel! Please set one up")); return; } if (await Utility.CheckReadWritePerms(context.Guild, channel) == false) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Sora is missing crucial perms. Owner has been notified!")); return; } //search for warnings with him if (all) { var userCases = guildDb.Cases.Where(x => x.UserId == user.Id && x.Type == Case.Warning)?.ToList(); if (userCases == null || userCases.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "User has no logged warnings!")); return; } int initialCount = userCases.Count; userCases.ForEach(x => guildDb.Cases.Remove(x)); await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Removed all warnings from user")); await PostWarningRemovalLog(channel, user, context.User, userCases.Count, initialCount); return; } var warning = guildDb.Cases.FirstOrDefault(x => x.UserId == user.Id && x.WarnNr == warnNr); if (warning == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Couldn't find specified warning!")); return; } int totalWarnings = guildDb.Cases.Count(x => x.UserId == user.Id && x.Type == Case.Warning); guildDb.Cases.Remove(warning); await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Removed specified warning")); await PostWarningRemovalLog(channel, user, context.User, 1, totalWarnings); } }
private EmbedBuilder CreateLog(int caseNr, Case modCase, SocketUser user, SocketGuild guild, SocketGuildUser mod = null, string reason = null, int warnNr = 0) { var eb = new EmbedBuilder() { Timestamp = DateTime.UtcNow, }; switch (modCase) { case Case.Ban: eb.Title = $"Case #{caseNr} | Ban 🔨"; eb.Color = _redBan; break; case Case.Kick: eb.Title = $"Case #{caseNr} | Kick 👢"; eb.Color = _orangeKick; break; case Case.Warning: eb.Title = $"Case #{caseNr} | Warning #{warnNr} ⚠"; eb.Color = _yellowWarning; break; } eb.AddField(x => { x.IsInline = false; x.Name = "User"; x.Value = $"**{Utility.GiveUsernameDiscrimComb(user)}** ({user.Id})"; }); eb.AddField(x => { x.IsInline = false; x.Name = "Moderator"; if (mod == null) { x.Value = "Unknown"; } else { x.Value = $"**{Utility.GiveUsernameDiscrimComb(mod)}** ({mod.Id})"; eb.ThumbnailUrl = mod.GetAvatarUrl() ?? Utility.StandardDiscordAvatar; } }); eb.AddField(x => { x.IsInline = false; x.Name = "Reason"; if (string.IsNullOrWhiteSpace(reason)) { using (SoraContext soraCon = new SoraContext()) { x.Value = $"Type `{Utility.GetGuildPrefix(guild, soraCon)}reason {caseNr} YourReason` to add it"; } } else { x.Value = reason; } }); return(eb); }
public async Task AddReason(SocketCommandContext context, int caseNr, string reason) { using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); var foundCase = guildDb.Cases.FirstOrDefault(x => x.CaseNr == caseNr); //check if case nr is valid if (foundCase == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Couldn't find case")); return; } //check if punishlogs channel exists var channel = context.Guild.GetTextChannel(guildDb.PunishLogsId); if (channel == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "There is no punishlogs channel set up!")); return; } //Check sora's perms if (await Utility.CheckReadWritePerms(context.Guild, channel) == false) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Sora laggs major permissions. Owner was notified")); return; } //Get old message var msg = (IUserMessage)await channel.GetMessageAsync(foundCase.PunishMsgId); if (msg == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Log doesn't exist anymore!")); return; } var mod = (SocketGuildUser)context.User; //if the case has a mod already check if its the same if (foundCase.ModId != 0) { //his case he can edit if (foundCase.ModId == mod.Id) { foundCase.Reason = reason; } else { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "This is not your case! You can't update the reason!")); return; } } else { //the log was auto generated and thus we must check if the user has the specific perms to claim this reason //the only autologged cases are bans. so we can hardcode if (!mod.GuildPermissions.Has(GuildPermission.BanMembers) && !Utility.IsSoraAdmin(mod)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You don't have ban permissions nor the {Utility.SORA_ADMIN_ROLE_NAME} role!")); return; } foundCase.ModId = mod.Id; foundCase.Reason = reason; } //reason was updated to change the post var eb = CreateLogReason(foundCase.CaseNr, foundCase.Type, foundCase.UserNameDisc, foundCase.UserId, mod, reason, foundCase.WarnNr); await msg.ModifyAsync(x => { x.Embed = eb.Build(); }); await soraContext.SaveChangesAsync(); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully updated reason on case {caseNr}")); }
public async Task Interact(InteractionType type, SocketUser user, SocketCommandContext context, SoraContext soraContext) { //FindUserMentioned var dbUser = Utility.GetOrCreateUser(user.Id, soraContext); switch (type) { case (InteractionType.Pat): dbUser.Interactions.Pats++; break; case (InteractionType.Hug): dbUser.Interactions.Hugs++; break; case (InteractionType.Kiss): dbUser.Interactions.Kisses++; break; case (InteractionType.Poke): dbUser.Interactions.Pokes++; break; case (InteractionType.Slap): dbUser.Interactions.Slaps++; break; case (InteractionType.High5): dbUser.Interactions.High5++; break; case (InteractionType.Punch): dbUser.Interactions.Punches++; break; default: await context.Channel.SendMessageAsync(":no_entry_sign: Something went horribly wrong :eyes:"); break; } await soraContext.SaveChangesAsync(); }
public async Task SearchTag() { try { using (var _soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(Context.Guild.Id, _soraContext); if (guildDb.Tags.Count < 1) { await ReplyAsync("", embed : Utility.ResultFeedback(Utility.YellowWarningEmbed, Utility.SuccessLevelEmoji[1], "Your Guild has no Tags yet!")); return; } List <string> tagList = new List <string>(); int pageAmount = (int)Math.Ceiling(guildDb.Tags.Count / 15.0); int addToJ = 0; int amountLeft = guildDb.Tags.Count; for (int i = 0; i < pageAmount; i++) { string addToList = ""; for (int j = 0; j < (amountLeft > 15 ? 15 : amountLeft); j++) { addToList += $"• `{guildDb.Tags[j + addToJ].Name}`\n"; } tagList.Add(addToList); amountLeft -= 15; addToJ += 15; } if (pageAmount > 1) { var pmsg = new PaginatedMessage() { Author = new EmbedAuthorBuilder() { IconUrl = Context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = Context.User.Username }, Color = Utility.PurpleEmbed, Title = $"Taglist of {Context.Guild.Name}", Options = new PaginatedAppearanceOptions() { DisplayInformationIcon = false, Timeout = TimeSpan.FromSeconds(30), InfoTimeout = TimeSpan.FromSeconds(30), }, Content = "Only the invoker may switch pages, ⏹ to stop the pagination", Pages = tagList }; await PagedReplyAsync(pmsg); } else { var eb = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { IconUrl = Context.User.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = Context.User.Username }, Color = Utility.PurpleEmbed, Title = $"Taglist of {Context.Guild.Name}", Description = tagList[0], Footer = new EmbedFooterBuilder() { Text = "Page 1/1" } }; await Context.Channel.SendMessageAsync("", embed : eb); } } } catch (Exception e) { Console.WriteLine(e); } }
public async Task AddDefaultRole(SocketCommandContext context, string roleName) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return; } var sora = context.Guild.CurrentUser; //Check if sora has manage role perms if (!sora.GuildPermissions.Has(GuildPermission.ManageRoles)) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Sora needs ManageRole permissions for Default roles to work!")); return; } //Try to find role IRole role = context.Guild.Roles.FirstOrDefault(x => x.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase)); bool wasCreated = false; //Role wasn't found if (role == null) { //he has the perms so he can create the role role = await context.Guild.CreateRoleAsync(roleName, GuildPermissions.None); wasCreated = true; } else { //check if the role found is ABOVE sora if so.. quit. (on life) var soraHighestRole = sora.Roles.OrderByDescending(x => x.Position).FirstOrDefault(); //Sora is below in the hirarchy if (soraHighestRole?.Position < role.Position) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "I cannot assign roles that are above me in the role hirachy!") .WithDescription("If this is not the case, open the server settings and move a couple roles around since discord doesn't refresh the position unless they are moved.")); return; } } //role was either found or created by sora.. using (SoraContext soraContext = new SoraContext()) { //check if it already exists var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); if (guildDb.DefaultRoleId == role.Id) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "This role already is the default role...")); return; } guildDb.DefaultRoleId = role.Id; guildDb.HasDefaultRole = true; await soraContext.SaveChangesAsync(); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully{(wasCreated ? " created and" : "")} added {roleName} as default join role!")); }