From fd7ea886d4b2be5bac8a8a9ea8c8084abfdf783e Mon Sep 17 00:00:00 2001 From: Runebaas Date: Sun, 7 May 2017 22:45:16 +0200 Subject: [PATCH] 4chan command - the beginning --- Geekbot.net/Lib/Dtos/FourChanDto.cs | 20 +++++++++ .../Lib/IClients/FourChanBoardClient.cs | 38 ++++++++++++++++ Geekbot.net/Modules/FourChan.cs | 43 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 Geekbot.net/Lib/Dtos/FourChanDto.cs create mode 100644 Geekbot.net/Lib/IClients/FourChanBoardClient.cs create mode 100644 Geekbot.net/Modules/FourChan.cs diff --git a/Geekbot.net/Lib/Dtos/FourChanDto.cs b/Geekbot.net/Lib/Dtos/FourChanDto.cs new file mode 100644 index 0000000..9d71d8c --- /dev/null +++ b/Geekbot.net/Lib/Dtos/FourChanDto.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace Geekbot.net.Lib.Dtos +{ + class FourChanDto + { + public class BoardList + { + public List Boards { get; set; } + } + + public class Board + { + public string board { get; set; } + public string title { get; set; } + public string ws_board { get; set; } + public string meta_description { get; set; } + } + } +} diff --git a/Geekbot.net/Lib/IClients/FourChanBoardClient.cs b/Geekbot.net/Lib/IClients/FourChanBoardClient.cs new file mode 100644 index 0000000..49fdc8d --- /dev/null +++ b/Geekbot.net/Lib/IClients/FourChanBoardClient.cs @@ -0,0 +1,38 @@ +using RestSharp; +using System; +using System.Collections.Generic; +using static Geekbot.net.Lib.Dtos.FourChanDto; + +namespace Geekbot.net.Lib.IClients +{ + + class FourChanBoardClient + { + private BoardList boards; + private static FourChanBoardClient instace; + + private FourChanBoardClient() + { + Console.WriteLine("Fetching Boards"); + var boardClient = new RestClient("https://a.4cdn.org"); + var boardRequest = new RestRequest("boards.json", Method.GET); + var boardResult = boardClient.Execute(boardRequest); + this.boards = boardResult.Data; + } + + public static FourChanBoardClient Boards() + { + if (instace == null) + { + instace = new FourChanBoardClient(); + } + + return instace; + } + + public List getBoards() + { + return this.boards.Boards; + } + } +} diff --git a/Geekbot.net/Modules/FourChan.cs b/Geekbot.net/Modules/FourChan.cs new file mode 100644 index 0000000..3cdf036 --- /dev/null +++ b/Geekbot.net/Modules/FourChan.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Discord.Commands; +using static Geekbot.net.Lib.Dtos.FourChanDto; +using Geekbot.net.Lib.IClients; + +namespace Geekbot.net.Modules +{ + public class FourChan : ModuleBase + { + [Command("4chan", RunMode = RunMode.Async), Summary("Get Something from 4chan")] + public async Task Chan([Summary("The someone")] string boardParam) + { + try + { + var boards = FourChanBoardClient.Boards(); + var board = new Board(); + foreach (var b in boards.getBoards()) + { + if (b.board.Equals(boardParam)) + { + board = b; + break; + } + } + if (board.board == boardParam) + { + await ReplyAsync($"{board.title} - {board.meta_description}"); + } else + { + await ReplyAsync("Sorry, that board does not exist..."); + } + } + catch (Exception e) + { + await ReplyAsync(e.Message); + } + } + } +} + +// var boards = new List["a", "b", "c", "d", "e", "f", "g", "gif", "h", "hr", "k", "m", "o", "p", "r", "s", "t", "u", "v", "vg", "vr", "w", "wg", "i", "ic", "r9k", "s4s", "cm", "hm", "lgbt", "y", "3", "aco", "adv", "an", "asp", "biz", "cgl", "ck", "co", "diy", "fa", "fit", "gd", "hc", "his", "int", "jp", "lit", "mlp", "mu", "n", "news", "out", "po", "pol", "qst", "sci", "soc" / sp / tg / toy / trv / tv / vp / wsg / wsr /];