4chan command - the beginning
This commit is contained in:
parent
8703a64556
commit
fd7ea886d4
3 changed files with 101 additions and 0 deletions
20
Geekbot.net/Lib/Dtos/FourChanDto.cs
Normal file
20
Geekbot.net/Lib/Dtos/FourChanDto.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Lib.Dtos
|
||||||
|
{
|
||||||
|
class FourChanDto
|
||||||
|
{
|
||||||
|
public class BoardList
|
||||||
|
{
|
||||||
|
public List<Board> 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
Geekbot.net/Lib/IClients/FourChanBoardClient.cs
Normal file
38
Geekbot.net/Lib/IClients/FourChanBoardClient.cs
Normal file
|
@ -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<BoardList>(boardRequest);
|
||||||
|
this.boards = boardResult.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FourChanBoardClient Boards()
|
||||||
|
{
|
||||||
|
if (instace == null)
|
||||||
|
{
|
||||||
|
instace = new FourChanBoardClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
return instace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Board> getBoards()
|
||||||
|
{
|
||||||
|
return this.boards.Boards;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
Geekbot.net/Modules/FourChan.cs
Normal file
43
Geekbot.net/Modules/FourChan.cs
Normal file
|
@ -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<string>["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 /];
|
Loading…
Reference in a new issue