8ball and architectural stuff

This commit is contained in:
dboerlage 2017-04-13 00:03:03 +02:00
parent 315526c32b
commit d3662b9934
No known key found for this signature in database
GPG key ID: BDA07B7D3FCF147F
4 changed files with 100 additions and 1 deletions

View file

@ -0,0 +1,26 @@
using System;
using System.Threading.Tasks;
using Discord.WebSocket;
namespace Geekbot.net.Lib
{
public class StatsRecorder
{
public static async Task Record(SocketMessage message)
{
await UpdateUserRecordTask(message);
}
private static Task UpdateUserRecordTask(SocketMessage message)
{
return Task.Run(() => UpdateUserRecord(message));
}
private static void UpdateUserRecord(SocketMessage message)
{
Console.WriteLine(message.Author.Username + " earned a point");
}
}
}

View file

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Discord.Commands;
namespace Geekbot.net.Modules
{
public class EightBall : ModuleBase
{
[Command("8ball"), Summary("Ask 8Ball a Question.")]
public async Task Ball([Remainder, Summary("The Question")] string echo)
{
var replies = new List<string> {
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",
"Reply hazy try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful"};
var rnd = new Random();
var answer = rnd.Next(replies.Count);
await ReplyAsync(replies[answer]);
}
}
}

View file

@ -19,5 +19,33 @@ namespace Geekbot.net.Modules
$"Account created at {userInfo.CreatedAt.Day}.{userInfo.CreatedAt.Month}.{userInfo.CreatedAt.Year}, that is {age} days ago\r\n" +
$"Currently {userInfo.Status}");
}
[Command("level"), Summary("Get a level based on a number")]
public async Task GetLevel([Summary("The (optional) user to get info for")] string xp)
{
var level = GetLevelAtExperience(int.Parse(xp));
await ReplyAsync(level.ToString());
}
public int GetExperienceAtLevel(int level){
double total = 0;
for (int i = 1; i < level; i++)
{
total += Math.Floor(i + 300 * Math.Pow(2, i / 7.0));
}
return (int) Math.Floor(total / 16);
}
public int GetLevelAtExperience(int experience) {
int index;
for (index = 0; index < 120; index++) {
if (GetExperienceAtLevel(index + 1) > experience)
break;
}
return index;
}
}
}

View file

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
namespace Geekbot.net
{
@ -70,7 +71,11 @@ namespace Geekbot.net
if (message == null) return;
if (message.Author.Username.Contains("Geekbot")) return;
Console.WriteLine(message.Channel + " - " + message.Author + " - " + message.Content);
var channel = (SocketGuildChannel) message.Channel;
Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content);
await StatsRecorder.Record(message);
}
}
}