Server Stats
This commit is contained in:
parent
9ff2e7cdc0
commit
468802d192
5 changed files with 59 additions and 34 deletions
33
Geekbot.net/Lib/LevelCalc.cs
Normal file
33
Geekbot.net/Lib/LevelCalc.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
class LevelCalc
|
||||
{
|
||||
private static 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 static int GetLevelAtExperience(int experience)
|
||||
{
|
||||
int index;
|
||||
|
||||
for (index = 0; index < 120; index++)
|
||||
{
|
||||
if (GetExperienceAtLevel(index + 1) > experience)
|
||||
break;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ namespace Geekbot.net.Modules
|
|||
public async Task Good([Summary("The someone")] IUser user)
|
||||
{
|
||||
var lastKarma = GetLastKarma();
|
||||
Console.WriteLine(lastKarma.ToString());
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
await ReplyAsync($"Sorry {Context.User.Username}, but you can't give yourself karma");
|
||||
|
|
|
@ -3,6 +3,8 @@ using System.Threading.Tasks;
|
|||
using Discord.Commands;
|
||||
using Discord;
|
||||
using Geekbot.net.Lib;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
|
@ -14,16 +16,33 @@ namespace Geekbot.net.Modules
|
|||
redis = redisClient;
|
||||
}
|
||||
|
||||
[Command("info"), Summary("Show some info about the bot.")]
|
||||
[Command("serverstats"), Summary("Show some info about the bot.")]
|
||||
public async Task getInfo()
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithTitle("Geekbot Information");
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
.WithIconUrl(Context.Guild.IconUrl)
|
||||
.WithName(Context.Guild.Name));
|
||||
eb.WithColor(new Color(110, 204, 147));
|
||||
|
||||
var created = Context.Guild.CreatedAt;
|
||||
var age = Math.Floor((DateTime.Now - created).TotalDays);
|
||||
|
||||
var messages = redis.Client.StringGet($"{Context.Guild.Id}-messages");
|
||||
var level = LevelCalc.GetLevelAtExperience((int)messages);
|
||||
|
||||
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
||||
eb.AddInlineField("Level", level)
|
||||
.AddInlineField("Messages", messages);
|
||||
|
||||
eb.AddInlineField("Version", "3.1")
|
||||
.AddInlineField("Uptime", "Not Calculated...");
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
|
||||
public static string FirstCharToUpper(string input)
|
||||
{
|
||||
if (String.IsNullOrEmpty(input))
|
||||
throw new ArgumentException("ARGH!");
|
||||
return input.First().ToString().ToUpper() + input.Substring(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ namespace Geekbot.net.Modules
|
|||
|
||||
var key = Context.Guild.Id + "-" + userInfo.Id;
|
||||
var messages = (int)redis.Client.StringGet(key + "-messages");
|
||||
var level = GetLevelAtExperience(messages);
|
||||
var level = LevelCalc.GetLevelAtExperience(messages);
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
|
@ -45,31 +45,6 @@ namespace Geekbot.net.Modules
|
|||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
|
||||
public async Task GetLevel(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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@ namespace Geekbot.net.Modules
|
|||
[Command("yt"), Summary("Search for something on youtube.")]
|
||||
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
||||
{
|
||||
// AIzaSyDQoJvtNXPVwIcUbSeeDEchnA4a-q1go0E
|
||||
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||
{
|
||||
ApiKey = "AIzaSyDQoJvtNXPVwIcUbSeeDEchnA4a-q1go0E",
|
||||
|
@ -36,7 +35,7 @@ namespace Geekbot.net.Modules
|
|||
|
||||
var result = searchListResponse.Items[0];
|
||||
|
||||
await ReplyAsync($"'{result.Snippet.Title}' from '{result.Snippet.ChannelTitle}' https://youtu.be/{result.Id.VideoId}");
|
||||
await ReplyAsync($"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue