Upgrading Dependencies and start restructure

This commit is contained in:
Runebaas 2017-09-14 20:24:04 +02:00
parent 44a80d76a9
commit e97ebf86ef
5 changed files with 54 additions and 78 deletions

View file

@ -1,28 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<ApplicationIcon>derp.ico</ApplicationIcon>
<Version>1.1.0</Version>
<Company>Pizza and Coffee Studios</Company>
<Authors>Pizza and Coffee Studios</Authors>
<Description>A Discord bot</Description>
<RepositoryUrl>https://github.com/pizzaandcoffee/Geekbot.net</RepositoryUrl>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Cleverbot" Version="0.9.0" />
<PackageReference Include="Discord.Net"> <PackageReference Include="Discord.Net">
<Version>1.0.0-rc</Version> <Version>1.0.2</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Google.Apis.YouTube.v3"> <PackageReference Include="Google.Apis.YouTube.v3">
<Version>1.25.0.760</Version> <Version>1.29.1.976</Version>
</PackageReference> </PackageReference>
<PackageReference Include="HtmlAgilityPack.NetCore"> <PackageReference Include="HtmlAgilityPack.NetCore">
<Version>1.5.0.1</Version> <Version>1.5.0.1</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="RestSharp.NetCore"> <PackageReference Include="RestSharp.NetCore">
<Version>105.2.4-rc4-24214-01</Version> <Version>105.2.3</Version>
</PackageReference> </PackageReference>
<PackageReference Include="StackExchange.Redis"> <PackageReference Include="StackExchange.Redis">
<Version>1.2.1</Version> <Version>1.2.6</Version>
</PackageReference> </PackageReference>
<PackageReference Include="System.Net.Http"> <PackageReference Include="System.Net.Http">
<Version>4.3.1</Version> <Version>4.3.2</Version>
</PackageReference> </PackageReference>
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
<PackageReference Include="System.Runtime.Serialization.Json"> <PackageReference Include="System.Runtime.Serialization.Json">
<Version>4.3.0</Version> <Version>4.3.0</Version>
</PackageReference> </PackageReference>

View file

@ -1,38 +0,0 @@
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;
}
}
}

View file

@ -2,6 +2,10 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
@ -16,9 +20,9 @@ namespace Geekbot.net
{ {
private CommandService commands; private CommandService commands;
private DiscordSocketClient client; private DiscordSocketClient client;
private DependencyMap map;
private IRedisClient redis; private IRedisClient redis;
private RedisValue token; private RedisValue token;
private ServiceCollection services;
private static void Main(string[] args) private static void Main(string[] args)
{ {
@ -30,7 +34,7 @@ namespace Geekbot.net
Console.WriteLine("========================================="); Console.WriteLine("=========================================");
Console.WriteLine("Starting..."); Console.WriteLine("Starting...");
Task.WaitAll(new Program().MainAsync()); new Program().MainAsync().GetAwaiter().GetResult();
} }
public async Task MainAsync() public async Task MainAsync()
@ -52,11 +56,11 @@ namespace Geekbot.net
redis.Client.StringSet("botOwner", ownerId); redis.Client.StringSet("botOwner", ownerId);
} }
map = new DependencyMap(); services = new ServiceCollection();
map.Add<ICatClient>(new CatClient()); services.AddSingleton<ICatClient>(new CatClient());
map.Add<IDogClient>(new DogClient()); services.AddSingleton<IDogClient>(new DogClient());
map.Add(redis); services.AddSingleton<IRandomClient>(new RandomClient());
map.Add<IRandomClient>(new RandomClient()); services.AddSingleton(redis);
Console.WriteLine("Connecting to Discord..."); Console.WriteLine("Connecting to Discord...");
@ -127,7 +131,7 @@ namespace Geekbot.net
// } // }
if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return; if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return;
var context = new CommandContext(client, message); var context = new CommandContext(client, message);
Task.Run(async () => await commands.ExecuteAsync(context, argPos, map)); Task.Run(async () => await commands.ExecuteAsync(context, argPos, services));
} }
public async Task HandleMessageReceived(SocketMessage messsageParam) public async Task HandleMessageReceived(SocketMessage messsageParam)

BIN
Geekbot.net/derp.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

BIN
derp.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB