public async Task <bool> PardonUser(SocketUser user, SocketGuild guild, SocketUser mod = null) { //MAKE SURE YOU CHECK PERMS IN MODULE U CUCK ♥ using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(guild.Id, soraContext); var cases = guildDb.Cases.Where(x => x.UserId == user.Id)?.ToList(); if (cases == null || cases.Count == 0) { return(false); } cases.ForEach(x => guildDb.Cases.Remove(x)); //Check if punishlogs exists var channel = guild.GetTextChannel(guildDb.PunishLogsId); if (channel == null) { guildDb.PunishLogsId = 0; await soraContext.SaveChangesAsync(); return(true); } await soraContext.SaveChangesAsync(); //check readwrite perms of sora if (await Utility.CheckReadWritePerms(guild, channel) == false) { return(true); } var eb = new EmbedBuilder() { Color = Utility.PurpleEmbed, Timestamp = DateTime.UtcNow, Title = "User Pardoned 🎈", Description = "All cases this user was involved with where removed from the guild's database. He starts fresh again." }; eb.AddField(x => { x.IsInline = false; x.Name = "User"; x.Value = $"**{Utility.GiveUsernameDiscrimComb(user)}** ({user.Id})"; }); if (mod != null) { eb.AddField(x => { x.IsInline = false; x.Name = "Moderator"; x.Value = $"**{Utility.GiveUsernameDiscrimComb(mod)}** ({mod.Id})"; }); eb.ThumbnailUrl = mod.GetAvatarUrl() ?? Utility.StandardDiscordAvatar; } await channel.SendMessageAsync("", embed : eb); } return(true); }
public async Task RestrictDj() { var invoker = (SocketGuildUser)Context.User; if (!invoker.GuildPermissions.Has(GuildPermission.Administrator) && !Utility.IsSoraAdmin(invoker)) { await ReplyAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You need Administrator permissions or the {Utility.SORA_ADMIN_ROLE_NAME} role to restrict music usage!")); return; } using (var _soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(Context.Guild.Id, _soraContext); if (guildDb.IsDjRestricted) { //MAKE IT UNRESTRICTED guildDb.IsDjRestricted = false; await _soraContext.SaveChangesAsync(); await ReplyAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully unrestricted all music commands!")); await ReplyAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully unrestricted all music commands!")); return; } //Restrict them bool created = false; if (Context.Guild.Roles.All(x => x.Name != Utility.SORA_DJ_ROLE_NAME)) { //DJ Role doesn't exist if (!Context.Guild.GetUser(Context.Client.CurrentUser.Id).GuildPermissions.Has(GuildPermission.ManageRoles)) { //CANT CREATE ONE EITHER await ReplyAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"The {Utility.SORA_DJ_ROLE_NAME} does not exist and Sora doesn't have manage role permission!").WithDescription( $"Either create the {Utility.SORA_DJ_ROLE_NAME} yourself (case sensitive) or give sora Manage Role permission and let him create it!")); return; } //Create the Role try { await Context.Guild.CreateRoleAsync(Utility.SORA_DJ_ROLE_NAME, GuildPermissions.None); } catch (Exception) { await ReplyAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"Couldn't Create role for some reason. Check perms!")); return; } created = true; } guildDb.IsDjRestricted = true; await _soraContext.SaveChangesAsync(); await ReplyAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully restricted all music commands{(created ? $" and created {Utility.SORA_DJ_ROLE_NAME} role!" : "!")}")); } }
private async Task <bool> Log(SocketGuild guild, SocketUser user, Case modCase, SocketGuildUser mod = null, string reason = null) { using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(guild.Id, soraContext); //check if punishlogs are initialized! if (guildDb.PunishLogsId == 0) { return(false); } var channel = guild.GetTextChannel(guildDb.PunishLogsId); //check if channel is null if (channel == null) { guildDb.PunishLogsId = 0; await soraContext.SaveChangesAsync(); return(false); } //channel does exist so check permissions if (await Utility.CheckReadWritePerms(guild, channel) == false) { return(false); } //both is alright //if there where previous cases get new case number int caseNr = 1; if (guildDb.Cases.Count > 0) { caseNr = GetCaseNumber(guildDb); } //if its a warning get warnNr int warnNr = 0; if (modCase == Case.Warning) { warnNr = guildDb.Cases.Count(x => x.UserId == user.Id && x.Type == Case.Warning) + 1; } //log final result var eb = CreateLog(caseNr, modCase, user, guild, mod, reason, warnNr); var msg = await channel.SendMessageAsync("", embed : eb); guildDb.Cases.Add(new ModCase() { CaseNr = caseNr, GuildForeignId = guild.Id, PunishMsgId = msg.Id, Reason = reason, Type = modCase, UserId = user.Id, ModId = mod?.Id ?? 0, UserNameDisc = Utility.GiveUsernameDiscrimComb(user), WarnNr = warnNr }); await soraContext.SaveChangesAsync(); } return(true); }
public async Task ClientOnUserJoined(SocketGuildUser socketGuildUser) { Task.Run(async() => { var guild = socketGuildUser.Guild; using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(guild.Id, soraContext); //Check if default role is even on if (!guildDb.HasDefaultRole) { return; } var sora = guild.CurrentUser; //Check if sora has manageRoles perms! if (!sora.GuildPermissions.Has(GuildPermission.ManageRoles)) { await(await guild.Owner.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Sora failed to add a default role!") .WithDescription( "He needs the ManageRole permissions to assign roles. The role must also be below his highest role!\n" + "Assigning default roles has been turned off. Fix the issue and then turn it back on by using the toggle command!")); guildDb.HasDefaultRole = false; await soraContext.SaveChangesAsync(); return; } //check if role still exists :P IRole role = guild.GetRole(guildDb.DefaultRoleId); //Role doesnt exist anymore, set defaultrole to false if (role == null) { await(await guild.Owner.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "Sora failed to add a default role!") .WithDescription("The default role doesn't exist anymore.\n" + "Assigning default roles has been turned off. Fix the issue and then turn it back on by using the toggle command!")); guildDb.HasDefaultRole = false; await soraContext.SaveChangesAsync(); return; } //role exists, is set to true and he has perms. so assign it await socketGuildUser.AddRoleAsync(role); } }); }
private async void CheckReminders(Object stateInfo) { try { using (var _soraContext = new SoraContext()) { List <Reminders> rems = new List <Reminders>(); rems = _soraContext.Reminders.ToList(); bool triggered = false; bool crucked = false; foreach (var reminder in rems) { if (reminder.Time.CompareTo(DateTime.UtcNow) <= 0) { triggered = true; var userToRemind = _client.GetUser(reminder.UserForeignId); if (userToRemind == null) { triggered = false; crucked = true; //remove if user is not reachable anymore if (reminder.Time.Add(TimeSpan.FromMinutes(CLEANUP_MINUTES)).CompareTo(DateTime.UtcNow) <= 0) { _soraContext.Reminders.Remove(reminder); } continue; } try { await(await userToRemind.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: Utility .ResultFeedback(Utility.PurpleEmbed, Utility.SuccessLevelEmoji[4], $"**Reminder** ⏰") .WithDescription($"{reminder.Message}")); } catch (Exception e) { //Ignore } _soraContext.Reminders.Remove(reminder); } } await _soraContext.SaveChangesAsync(); if (crucked) { _timer.Change(TimeSpan.FromSeconds(CRUCKED_SECONDS), TimeSpan.FromSeconds(CRUCKED_SECONDS)); Console.WriteLine($"CHANGED TIMER INTERVAL TO *CRUCKED*: {CRUCKED_SECONDS}"); } else if (triggered) { ChangeToClosestInterval(); } } } catch (Exception e) { await SentryService.SendMessage(e.ToString()); } }
public async Task SetStarLimit([Summary("WHOLE number of amount needed")] int amount) { if (CheckPerms(Context) == false) { await ReplyAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You need Administrator or Mange Channels permission to set the starlimit!")); return; } if (amount > 100) { amount = 100; } if (amount < 1) { amount = 1; } using (var _soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(Context.Guild.Id, _soraContext); guildDb.StarMinimum = amount; await _soraContext.SaveChangesAsync(); await ReplyAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully changed minimum Star requirement to {amount}")); } }
public async Task RemoveStarChannel() { if (CheckPerms(Context) == false) { await ReplyAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You need Administrator or Mange Channels permission or the {Utility.SORA_ADMIN_ROLE_NAME} role to remove the starboard channel")); return; } using (var _soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(Context.Guild.Id, _soraContext); if (guildDb.StarChannelId == 0) { await ReplyAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "No Starboard channel set!")); return; } guildDb.StarChannelId = 0; await _soraContext.SaveChangesAsync(); await ReplyAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully removed the starboard channel")); } }
public async Task RemoveTag(SocketCommandContext context, SoraContext soraContext, string name, bool admin) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); //Check if tag exists var result = guildDb.Tags.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (result == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"No tag was found with the name:").WithDescription($"{name}")); return; } //Check if creator or admin if (!admin && result.CreatorId != context.User.Id) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You are neither Administrator nor the Creator of the Tag!")); return; } //delete Tag guildDb.Tags.Remove(result); await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Tag was successfully removed!")); }
public async Task ToggleLeaveEmbed(SocketCommandContext context) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return; } using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); guildDb.EmbedLeave = !guildDb.EmbedLeave; await soraContext.SaveChangesAsync(); if (guildDb.EmbedLeave) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Leave announcements will now be done in embeds!")); } else { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Leave announcements will now be done as normal messages!")); } } }
public async Task RestrictTagCreation() { var invoker = (SocketGuildUser)Context.User; if (!invoker.GuildPermissions.Has(GuildPermission.Administrator) && !Utility.IsSoraAdmin(invoker)) { await ReplyAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You need Administrator permissions or the {Utility.SORA_ADMIN_ROLE_NAME} role to change these settings!")); return; } using (var _soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(Context.Guild.Id, _soraContext); //Check if the sora admin role even exists! if (!Utility.CheckIfSoraAdminExists(Context.Guild) && !guildDb.RestrictTags) { await ReplyAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"The {Utility.SORA_ADMIN_ROLE_NAME} Role does not exist! Please create it manually or use \"{Utility.GetGuildPrefix(Context.Guild, _soraContext)}createAdmin\"")); return; } guildDb.RestrictTags = !guildDb.RestrictTags; await _soraContext.SaveChangesAsync(); await ReplyAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"{(guildDb.RestrictTags ? $"Set the Tag Restriction to TRUE!\n=> Users need the {Utility.SORA_ADMIN_ROLE_NAME} Role to create Tags" : $"Set the Tag Restriction to FALSE!\n=> Everyone can create Tags")}")); } }
public async Task RemoveFavWaifu() { using (var soraContext = new SoraContext()) { var userdb = Utility.OnlyGetUser(Context.User.Id, soraContext); if (userdb == null) { await ReplyAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You don't have a favorite waifu..." )); return; } userdb.FavoriteWaifu = -1; await soraContext.SaveChangesAsync(); await ReplyAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully removed favorite waifu." )); } }
public async Task AddWaifu(SocketCommandContext context, string name, string image, int rarity) { using (var soraContext = new SoraContext()) { // check if waifu already exists if (soraContext.Waifus.Any(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase))) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"{name} already exists in the Database!" )); return; } var waifu = new Waifu() { ImageUrl = image, Name = name, Rarity = GetRarityByInt(rarity), }; soraContext.Waifus.Add(waifu); await soraContext.SaveChangesAsync(); var withId = soraContext.Waifus.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); AddWaifuToCache(withId); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"You added {name} with ID {waifu.Id}" )); } }
public async Task IncreaseEpOnMessageReceive(SocketMessage msg) { using (var _soraContext = new SoraContext()) { //Don't prcoess the command if it was a system message var message = msg as SocketUserMessage; if (message == null) { return; } //dont process if it was a bot if (message.Author.IsBot) { return; } //Create a command Context var context = new SocketCommandContext(_client, message); if (context.IsPrivate) { return; } var userDb = Utility.GetOrCreateUser(context.User.Id, _soraContext); //Check for cooldown if (userDb.CanGainAgain.CompareTo(DateTime.UtcNow) > 0) { return; } //Reset cooldown userDb.CanGainAgain = DateTime.UtcNow.AddSeconds(10); int previousLevel = CalculateLevel(userDb.Exp); var epGain = (int)Math.Round(context.Message.Content.Length / 10F); if (epGain > 50) { epGain = 50; } userDb.Exp += epGain; int currentLevel = CalculateLevel(userDb.Exp); await _soraContext.SaveChangesAsync(); //Guild user gain Task.Run(async() => { await _roleService.OnUserExpGain(epGain, context); }); //Notifying if (previousLevel != currentLevel && userDb.Notified) { var eb = new EmbedBuilder() { Color = new Color(255, 204, 77), Title = $"🏆 You leveled up! You are now level {currentLevel} \\ (•◡•) /" }; await(await context.User.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: eb); } } }
public async Task UnboxWaifu(SocketCommandContext context) { using (var soraContext = new SoraContext()) { var userdb = Utility.GetOrCreateUser(context.User.Id, soraContext); // check cash if (userdb.Money < BOX_COST) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You don't have enough Sora Coins! You need {BOX_COST} SC." )); return; } // remove money userdb.Money -= BOX_COST; // open box var waifus = new List <Waifu>(); for (int i = 0; i < BOX_CARD_AMOUNT; i++) { var waifu = GetRandomFromBox(); waifus.Add(waifu); // add to user GiveWaifuToId(context.User.Id, waifu.Id, userdb); } // save already if smth down there fails at least he got everything. await soraContext.SaveChangesAsync(); // show what he got var ordered = waifus.OrderByDescending(x => x.Rarity).ToArray(); var eb = new EmbedBuilder() { Title = "Congrats! You've got some nice waifus", Description = $"You opened a regular WaifuBox for {BOX_COST} SC.", Footer = Utility.RequestedBy(context.User), Color = Utility.PurpleEmbed, ImageUrl = ordered[0].ImageUrl }; foreach (var waifu in ordered) { eb.AddField(x => { x.IsInline = true; x.Name = waifu.Name; x.Value = $"Rarity: {GetRarityString(waifu.Rarity)}\n" + $"[Image Url]({waifu.ImageUrl})\n" + $"*ID: {waifu.Id}*"; }); } await context.Channel.SendMessageAsync("", embed : eb); } }
private async Task ClientOnJoinedGuild(SocketGuild socketGuild) { Task.Run(async() => { //Notify discordbots that we joined a new guild :P try { await _guildCount.UpdateCount(_client.Guilds.Count); } catch (Exception e) { Console.WriteLine(e); } using (var soraContext = new SoraContext()) { var guild = Utility.GetOrCreateGuild(socketGuild.Id, soraContext); //AUTO CREATE SORA ADMIN ROLE //var created = await Utility.CreateSoraRoleOnJoinAsync(socketGuild, _client, soraContext).ConfigureAwait(false); /* * if (created) * { * guild.RestrictTags = socketGuild.MemberCount > 100; * }*/ await soraContext.SaveChangesAsync(); try { string prefix = Utility.GetGuildPrefix(socketGuild, soraContext); await(await socketGuild.Owner.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: Utility.ResultFeedback(Utility.BlueInfoEmbed, Utility.SuccessLevelEmoji[3], $"Hello there (≧∇≦)/") .WithDescription($"I'm glad you invited me over :)\n" + $"You can find the [list of commands and help here](http://git.argus.moe/serenity/SoraBot-v2/wikis/home)\n" + $"To restrict tag creation and Sora's mod functions you must create\n" + $"a {Utility.SORA_ADMIN_ROLE_NAME} Role so that only the ones carrying it can create\n" + $"tags or use Sora's mod functionality. You can make him create one with: " + $"`{prefix}createAdmin`\n" + $"You can leave tag creation unrestricted if you want but its not\n" + $"recommended on larger servers as it will be spammed.\n" + $"**Sora now has a Dashboard**\n" + $"You can [find the dashboard here](http://argonaut.pw/Sora/) by clicking the login\n" + $"button in the top right. It's still in pre-alpha but allows you to\n" + $"customize levels and level rewards as well as other settings. It is required\n" + $"for proper setup of leveling.\n" + $"PS: Standard Prefix is `$` but you can change it with:\n" + $"`@Sora prefix yourPrefix`\n").WithThumbnailUrl(socketGuild.IconUrl ?? Utility.StandardDiscordAvatar).AddField("Support", $"You can find the [support guild here]({Utility.DISCORD_INVITE})")); } catch (Exception e) { Console.WriteLine(e); } } //inform me of joining await SentryService.SendMessage($"**JOINED GUILD**\nName: {socketGuild.Name}\nID: {socketGuild.Id}\nUsers: {socketGuild.MemberCount}\nOwner: {Utility.GiveUsernameDiscrimComb(socketGuild.Owner)}"); //TODO WELCOME MESSAGE }); }
public async Task Client_MessageReceived(SocketMessage msg, IServiceProvider _services) { if (msg.Author.Id == 270931284489011202 || msg.Author.Id == 276304865934704642) { return; } if (msg.MentionedUsers.Count < 1) { return; } using (var soraContext = new SoraContext()) { //Get GUILD PREFIX string prefix = Utility.GetGuildPrefixFast(soraContext, ((SocketGuildChannel)msg.Channel).Guild.Id, "$"); if (msg.Content.StartsWith(prefix)) { return; } foreach (var user in msg.MentionedUsers) { var userDb = Utility.GetOrCreateUser(user.Id, soraContext); if (userDb.Afk == null) { return; //if null none was set up } if (userDb.Afk.IsAfk) { //CAN TRIGGER AGAIN? if (userDb.Afk.TimeToTriggerAgain.CompareTo(DateTime.UtcNow) > 0) { return; } userDb.Afk.TimeToTriggerAgain = DateTime.UtcNow.AddSeconds(SECONDS_AFTER_REPOST); var eb = new EmbedBuilder() { Color = Utility.PurpleEmbed, Author = new EmbedAuthorBuilder() { IconUrl = user.GetAvatarUrl() ?? Utility.StandardDiscordAvatar, Name = $"{user.Username} is currently AFK" }, Description = userDb.Afk.Message }; await soraContext.SaveChangesAsync(); await msg.Channel.SendMessageAsync("", embed : eb); } } } }
public async Task SendMoney(SocketCommandContext context, int amount, ulong userId) { using (var soraContext = new SoraContext()) { // get current userDb var userdb = Utility.OnlyGetUser(context.User.Id, soraContext); // check if user exists and if he has the money if (userdb == null || userdb.Money < amount) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "You don't have enough Sora Coins!")); return; } // get or create other userDb var otherDb = Utility.GetOrCreateUser(userId, soraContext); // transfer the money userdb.Money -= amount; otherDb.Money += amount; // save changes await soraContext.SaveChangesAsync(); } var user = context.Client.GetUser(userId); // send message to other user try { if (user == null) { throw new Exception(); } await(await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: Utility.ResultFeedback( Utility.PurpleEmbed, Utility.SuccessLevelEmoji[4], $"💰 You've received {amount} SC from {Utility.GiveUsernameDiscrimComb(context.User)} !" )); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"You have successfully transfered {amount} SC to {Utility.GiveUsernameDiscrimComb(user)}! They've been notified." )); } catch (Exception e) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.YellowWarningEmbed, Utility.SuccessLevelEmoji[1], $"You have successfully transfered {amount} SC to {(user == null ? userId.ToString() : Utility.GiveUsernameDiscrimComb(user))}!." ).WithDescription("But I failed to send him/her a DM, they have probably disabled that feature. You may want to notify him/her yourself.")); } }
public async Task UpdateGuildPrefix(SocketCommandContext context, SoraContext soraContext, string prefix) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); guildDb.Prefix = prefix; await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Prefix in this Guild was changed to `{prefix}`")); }
// Ban user Command public async Task <bool> BanUser(ulong id, string reason) { if (!_bannedUsers.TryAdd(id, true)) { return(false); } // Add to DB using (var soraContext = new SoraContext()) { if (string.IsNullOrWhiteSpace(reason)) { reason = ""; } soraContext.Bans.Add(new Ban() { UserId = id, BannedAt = DateTime.UtcNow, Reason = reason }); await soraContext.SaveChangesAsync(); } // notify other shards to ban user int port = int.Parse(ConfigService.GetConfigData("port")); for (int i = 0; i < Utility.TOTAL_SHARDS; i++) { if (i == Utility.SHARD_ID) { continue; } try { using (var httpClient = new HttpClient()) using (var request = new HttpRequestMessage(HttpMethod.Post, $"http://localhost:{(port+i)}/api/SoraApi/BanEvent/")) { string json = JsonConvert.SerializeObject(new { userId = id }); request.Content = new StringContent(json); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await httpClient.SendAsync(request); response.Dispose(); } } catch (Exception e) { Console.WriteLine(e); await SentryService.SendMessage($"COULDN'T SEND BAN EVENT TO SHARD {i} FOR ID: {id}"); } } return(true); }
public async Task ClientOnUserJoined(SocketGuildUser socketGuildUser) { Task.Run(async() => { using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(socketGuildUser.Guild.Id, soraContext); //check if channel is initialized if (guildDb.WelcomeChannelId == 0) { return; } //check if channel exists var channel = socketGuildUser.Guild.GetTextChannel(guildDb.WelcomeChannelId); if (channel == null) { guildDb.WelcomeChannelId = 0; await soraContext.SaveChangesAsync(); return; } //check sendmessageperms perms if (await Utility.CheckReadWritePerms(socketGuildUser.Guild, channel) == false) { return; } //he has perms and channel exists so post the message string message = guildDb.WelcomeMessage; if (string.IsNullOrWhiteSpace(message)) { message = _defaultJoin; } string editedMessage = ReplaceInfo(socketGuildUser, message); if (guildDb.EmbedWelcome) { var eb = new EmbedBuilder() { Color = Utility.PurpleEmbed, Description = editedMessage }; await channel.SendMessageAsync("", embed: eb); } else { await channel.SendMessageAsync(editedMessage); } } }); }
public async Task ToggleDefaultRole(SocketCommandContext context) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return; } using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); //if he plans to turn it on check if role exists if (!guildDb.HasDefaultRole) { //check if role still exists :P IRole role = context.Guild.GetRole(guildDb.DefaultRoleId); //Role doesnt exist anymore if (role == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "The default role doesn't exist! Please set one before changing this to true.")); 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; } //set it to true guildDb.HasDefaultRole = true; await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Default role is now activated!")); } else { guildDb.HasDefaultRole = false; await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Default role is now deactivated!")); } await soraContext.SaveChangesAsync(); } }
public async Task <bool> SetLeaveChannel(SocketCommandContext context, SocketChannel channel) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return(false); } using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); guildDb.LeaveChannelId = channel.Id; await soraContext.SaveChangesAsync(); } return(true); }
public async Task <bool> SetWelcomeMessage(SocketCommandContext context, string message) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return(false); } using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); guildDb.WelcomeMessage = message; await soraContext.SaveChangesAsync(); } return(true); }
/// <summary> /// Tries to find a Guild and if it can't it'll create one and already save! /// </summary> public static async Task <Guild> GetOrSetAndGetGuild(ulong id, SoraContext context) { var guild = await context.Guilds.FindAsync(id).ConfigureAwait(false); if (guild != null) { return(guild); } // Create guild, save it and give it back guild = new Guild(id); // ReSharper disable once MethodHasAsyncOverload context.Guilds.Add(guild); await context.SaveChangesAsync().ConfigureAwait(false); return(guild); }
public async Task DeletePunishLogsChannel(SocketCommandContext context) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return; } using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); guildDb.PunishLogsId = 0; await soraContext.SaveChangesAsync(); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully removed punishlogs channel")); }
public async Task RemoveLeaveChannel(SocketCommandContext context) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return; } using (SoraContext soraContext = new SoraContext()) { var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); guildDb.LeaveChannelId = 0; await soraContext.SaveChangesAsync(); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback(Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "Successfully removed Leave channel. No leave announcements will be done anymore")); }
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 RemoveSarFromList(SocketCommandContext context, string roleName) { //check perms if (await Utility.HasAdminOrSoraAdmin(context) == false) { return; } var sora = context.Guild.CurrentUser; //Try to find role var role = context.Guild.Roles.FirstOrDefault(x => x.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase)); //Role wasn't found if (role == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "The Specified Role doesn't exist!")); return; } //role was found using (SoraContext soraContext = new SoraContext()) { //Check if its self-assignable var guildDb = Utility.GetOrCreateGuild(context.Guild.Id, soraContext); var sarRole = guildDb.SelfAssignableRoles.FirstOrDefault(x => x.RoleId == role.Id); if (sarRole == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], "This role is not self-assignable!")); return; } //Role is self assignable guildDb.SelfAssignableRoles.Remove(sarRole); await soraContext.SaveChangesAsync(); } await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], $"Successfully removed {role.Name} from self-assignable roles!")); }
// UnBan user Command public async Task <bool> UnBanUser(ulong id) { if (!_bannedUsers.TryRemove(id, out _)) { return(false); } // remove from DB using (var soraContext = new SoraContext()) { soraContext.Bans.Remove(soraContext.Bans.FirstOrDefault(x => x.UserId == id)); await soraContext.SaveChangesAsync(); } // notify other shards to ban user int port = int.Parse(ConfigService.GetConfigData("port")); for (int i = 0; i < Utility.TOTAL_SHARDS; i++) { if (i == Utility.SHARD_ID) { continue; } try { using (var httpClient = new HttpClient()) using (var request = new HttpRequestMessage(HttpMethod.Post, $"http://localhost:{(port+i)}/api/SoraApi/UnBanEvent/")) { string json = JsonConvert.SerializeObject(new { userId = id }); request.Content = new StringContent(json); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await httpClient.SendAsync(request); response.Dispose(); } } catch (Exception e) { Console.WriteLine(e); await SentryService.SendMessage($"COULDN'T SEND UNBAN EVENT TO SHARD {i} FOR ID: {id}"); } } return(true); }
public async Task Divorce(SocketCommandContext context, ulong Id) { using (var soraContext = new SoraContext()) { var userDb = Utility.OnlyGetUser(context.User.Id, soraContext); if (userDb == null || userDb.Marriages.Count == 0) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You have no marriages yet!")); return; } var result = userDb.Marriages.FirstOrDefault(x => x.PartnerId == Id); if (result == null) { await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.RedFailiureEmbed, Utility.SuccessLevelEmoji[2], $"You are not married to that person")); return; } var parterDb = Utility.OnlyGetUser(Id, soraContext); userDb.Marriages.Remove(result); var remove = parterDb.Marriages.FirstOrDefault(x => x.PartnerId == context.User.Id); if (remove != null) { parterDb.Marriages.Remove(remove); } await soraContext.SaveChangesAsync(); await context.Channel.SendMessageAsync("", embed : Utility.ResultFeedback( Utility.GreenSuccessEmbed, Utility.SuccessLevelEmoji[0], "You have been successfully divorced")); var divorced = context.Client.GetUser(Id); if (divorced != null) { await(await divorced.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: Utility.ResultFeedback( Utility.BlueInfoEmbed, Utility.SuccessLevelEmoji[3], $"{Utility.GiveUsernameDiscrimComb(context.User)} has divorced you 😞")); } } }