Fuck Singletons

This commit is contained in:
dboerlage 2017-04-13 23:20:05 +02:00
parent 2e8d4b6125
commit 3ce207749f
No known key found for this signature in database
GPG key ID: BDA07B7D3FCF147F
7 changed files with 120 additions and 14 deletions

53
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,53 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/Geekbot.net/bin/Debug/netcoreapp1.1/Geekbot.net.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/<target-framework>/Geekbot.net.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

17
.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ ],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
]
}

13
Geekbot.net.userprefs Normal file
View file

@ -0,0 +1,13 @@
<Properties StartupConfiguration="{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}|Default">
<MonoDevelop.Ide.Workbench ActiveDocument="Geekbot.net/Program.cs">
<Files>
<File FileName="Geekbot.net/Program.cs" Line="87" Column="9" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<MultiItemStartupConfigurations />
</Properties>

View file

@ -1,8 +1,4 @@
using System; using RestSharp;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using RestSharp;
namespace Geekbot.net.Modules namespace Geekbot.net.Modules
{ {

View file

@ -0,0 +1,30 @@
using System;
using StackExchange.Redis;
namespace Geekbot.net.Lib
{
public sealed class RedisSingleton
{
private RedisSingleton()
{
var redis = ConnectionMultiplexer.Connect("localhost:6379");
if (redis.IsConnected)
{
Console.WriteLine("Connection to Redis Enstablished");
}
else
{
Console.WriteLine("Connection to Redis Failed");
}
}
private static readonly Lazy<RedisSingleton> lazy = new Lazy<RedisSingleton>(() => new RedisSingleton());
public static RedisSingleton Instance
{
get
{
return lazy.Value;
}
}
}
}

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.WebSocket; using Discord.WebSocket;
using Geekbot.net.Lib;
namespace Geekbot.net.Lib namespace Geekbot.net.Lib
{ {
@ -12,18 +13,19 @@ namespace Geekbot.net.Lib
public StatsRecorder(SocketMessage message) public StatsRecorder(SocketMessage message)
{ {
this.message = message; this.message = message;
var db = new RedisSingleton();
} }
public async Task UpdateUserRecordAsync() public async Task UpdateUserRecordAsync()
{ {
Console.WriteLine(message.Author.Username + " earned a point"); // Console.WriteLine(message.Author.Username + " earned a point");
await Task.FromResult(true); await Task.FromResult(true);
} }
public async Task UpdateGuildRecordAsync() public async Task UpdateGuildRecordAsync()
{ {
var channel = (SocketGuildChannel) message.Channel; var channel = (SocketGuildChannel) message.Channel;
Console.WriteLine(channel.Guild.Name + " earned a point"); // Console.WriteLine(channel.Guild.Name + " earned a point");
await Task.FromResult(true); await Task.FromResult(true);
} }
} }

View file

@ -18,13 +18,8 @@ namespace Geekbot.net.Modules
{ {
var request = new RestRequest("meow.php", Method.GET); var request = new RestRequest("meow.php", Method.GET);
var response = catClient.Client.Execute<CatObject>(request); dynamic response = catClient.Client.Execute<dynamic>(request);
await ReplyAsync(response.Data.file); await ReplyAsync(response.Data["file"]);
} }
} }
public class CatObject
{
public string file {get;set;}
}
} }