internal static async Task SearchAndPost(string searchTerm, SocketMessage e, bool isSafeSearch) { BooruResult result = Derpi_Search.SearchForImage(searchTerm, isSafeSearch); string message = ""; if (result.link != null) { if (isSafeSearch) { message += "<:coral:279967024438837249> <Coral returns happily with the picture you wanted!> \n`" + searchTerm + "`\n" + result.link; } else { message += "<:coral:279967024438837249> <Coral returns excitedly with the picture you wanted!> \n`" + searchTerm + "`\n" + result.link; } if (result.score != null) { message += "\n`Score:" + result.score + "`"; } if (result.artist != null) { message += "\n`" + result.artist + "`"; } } else { message += "<Coral returns sadly, she couldn't find anything for `" + searchTerm + "` > :cry: "; } await e.Channel.SendMessageAsync(message); }
private async Task HandleCommands(SocketMessage e) { //is this a DM and what is the author's name? bool isDM = false; string senderName = e.Author.Username; string lowerContent = e.Content.ToLower(); SocketGuildUser user = null; try { user = (SocketGuildUser)e.Author; } catch { Console.WriteLine("PM from " + e.Author.Username + ":"); Console.WriteLine(e.Content); } if (e.Channel.GetType() == typeof(SocketDMChannel)) { isDM = true; } else { senderName = user.Nickname ?? e.Author.Username; } //Show help to user //Basic echo function if (Config.adminIDs.Contains(e.Author.Id) && lowerContent.StartsWith("!echo ")) { await e.Channel.SendMessageAsync(e.Content.Substring(6)); await e.DeleteAsync(); } //Derpi search if (!IsAuthor(e) && lowerContent.StartsWith("!derpi ")) { //get search term string searchTerm = e.Content.Substring(7); //find a result //post resulting image try { if (Config.nsfwChannelIDs.Contains(e.Channel.Id)) { await Derpi_Search.SearchAndPost(searchTerm, e, false); } else { await Derpi_Search.SearchAndPost(searchTerm, e, true); } } catch { await e.Channel.SendMessageAsync("`**-Coral runs around because everything is broken and on fire!!!!-**`"); } } //E621 search if (!IsAuthor(e) && e.Channel.Id == 282826164127399936 && lowerContent.StartsWith("!e621 ")) { //get search term string searchTerm = e.Content.Substring(6); //find a result //post resulting image await E621Search.SearchAndPost(searchTerm, e); } //Coin Flip if (!IsAuthor(e) && lowerContent.StartsWith("!flip")) { Random random = new Random(); await e.Channel.SendMessageAsync(random.Next(2) == 0? "`Heads`" : "`Tails`"); } if (!IsAuthor(e) && lowerContent.StartsWith("!ghost")) { Random random = new Random(); await e.Channel.SendMessageAsync("**-Coral baps the ghost!-** <Go away spooker!>"); } //Dice Rolling if (!IsAuthor(e) && lowerContent.StartsWith("!roll")) { string sub = ""; if (e.Content.Length > 6) { sub = e.Content.Substring(6); } else { sub = "1d20"; } //await DiceRoll(sub, e); await Dice_Roller.DiceRoll(sub, e); } //8-ball if (!IsAuthor(e) && lowerContent.StartsWith("!8ball")) { await EightBall(e); } //Spin if (!IsAuthor(e) && lowerContent.StartsWith("!spin")) { await e.Channel.SendFileAsync("UkY5mCJ.gif"); } //F To pay respects if (!IsAuthor(e) && lowerContent.StartsWith("!f")) { string[] sub = e.Content.Split(' '); if (sub[0].Length == 2) { await e.Channel.SendMessageAsync("**-" + e.Author.Mention + " pays their respects.-** :pray:"); } } //Daily fact if (!IsAuthor(e) && lowerContent.StartsWith("!fact")) { await DailyFact(e); } //Channel ID if (!IsAuthor(e) && lowerContent.StartsWith("!channelID")) { await e.Channel.SendMessageAsync("This channel's ID is" + e.Channel.Id); } //Lennny Face if (!IsAuthor(e) && lowerContent.StartsWith("!lenny")) { await e.Channel.SendMessageAsync("( ͡° ͜ʖ ͡°)"); } //Set Role if (!IsAuthor(e) && lowerContent.StartsWith("!set")) { await SetRole(e); } //Unset Role if (!IsAuthor(e) && lowerContent.StartsWith("!unset")) { await UnsetRole(e); } //hug if (!IsAuthor(e) && lowerContent.StartsWith("!hug")) { string thing = null; if (e.Content.Length > 5) { thing = e.Content.Substring(5); } if ((e.MentionedUsers.Count <= 0 && thing == null) || isDM) { await e.Channel.SendMessageAsync("**-CoralBot hugs " + senderName + ", who now smells like fish-**"); } else if (e.MentionedUsers.Count <= 0) { await e.Channel.SendMessageAsync("**-:hearts: `" + senderName + "` hugs `" + thing + "` :hearts: -**"); } else if (e.MentionedUsers.Count == 1) { SocketGuildUser mentionUser = (SocketGuildUser)e.MentionedUsers.ElementAt <SocketUser>(0); string target = mentionUser.Nickname ?? mentionUser.Username; await e.Channel.SendMessageAsync("**-:hearts: `" + senderName + "` hugs `" + target + "` :hearts: -**"); } } if (!IsAuthor(e) && lowerContent.StartsWith("!killme")) { if (e.MentionedUsers.Count <= 0) { await e.Channel.SendMessageAsync("**-CoralBot hugs " + senderName + "-** <No!>"); } } //Bap if (!IsAuthor(e) && lowerContent.StartsWith("!bap")) { string thing = null; if (e.Content.Length > 5) { thing = e.Content.Substring(5); } if ((e.MentionedUsers.Count <= 0 && thing == null) || isDM) { await e.Channel.SendMessageAsync("**-CoralBot baps " + senderName + " right on the nose with a rolled up newspaper-** :newspaper2:"); } else if (e.MentionedUsers.Count <= 0) { await e.Channel.SendMessageAsync("**-`" + senderName + "` baps `" + thing + "` with a rolled up newspaper-** :newspaper2:"); } else if (e.MentionedUsers.Count == 1) { SocketGuildUser mentionUser = (SocketGuildUser)e.MentionedUsers.ElementAt <SocketUser>(0); string target = mentionUser.Nickname ?? mentionUser.Username; await e.Channel.SendMessageAsync("**-`" + senderName + "` baps `" + target + "` with a rolled up newspaper-** :newspaper2:"); } } //About Bot if (!IsAuthor(e) && lowerContent.StartsWith("!about")) { await e.Channel.SendMessageAsync(Config.about); } //Help Menu if (!IsAuthor(e) && lowerContent.StartsWith("!help")) { //await e.Author.SendMessage(@"```Markdown await e.Channel.SendMessageAsync(@"```Markdown CoralBot Commands ============== !set Watcher - give yourself the Watcher role !unset Watcher - remove the role from yourself !derpi [search terms] - Find an image on Derpibooru. (NSFW results limited to NSFW channel) !e621 [search terms] - Find an image on e621. (Only works in the nsfw-others channel) !flip - Flip a coin, heads or tails. !roll [dice or modifiers] - Rolls a d20 dice, or your specified dice (eg: 2d8+5-1d20) !8ball [your question] - Ask the magic 8-ball your question. !fact - Get a fun fact of the day! !spin - Spin the Red. !lenny - Lenny Face ( ͡° ͜ʖ ͡°) !f - Pay your respects !hug [user or thing] - Hug CoralBot, someone or something !bap [user or thing] - Bap CoralBot, someone or something with a rolled up newspaper !ghost - Tell the spooker to go away !about - Information about CoralBot. !help - Get command list. ```"); } if (!IsAuthor(e) && lowerContent.StartsWith("@Coral-Bot")) { if (e.MentionedUsers.Count == 1) { } } }