Updated Help Command and code update
This commit is contained in:
parent
c82d6ec666
commit
8911123b78
23 changed files with 248 additions and 238 deletions
|
@ -5,9 +5,9 @@ namespace Geekbot.net.Lib
|
|||
{
|
||||
public class CheckEmImageProvider : ICheckEmImageProvider
|
||||
{
|
||||
private string[] checkEmImageArray;
|
||||
private int totalCheckEmImages;
|
||||
private Random rnd;
|
||||
private readonly string[] checkEmImageArray;
|
||||
private readonly Random rnd;
|
||||
private readonly int totalCheckEmImages;
|
||||
|
||||
public CheckEmImageProvider()
|
||||
{
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
class FortunesProvider : IFortunesProvider
|
||||
internal class FortunesProvider : IFortunesProvider
|
||||
{
|
||||
private string[] fortuneArray;
|
||||
private int totalFortunes;
|
||||
private Random rnd;
|
||||
private readonly string[] fortuneArray;
|
||||
private readonly Random rnd;
|
||||
private readonly int totalFortunes;
|
||||
|
||||
public FortunesProvider()
|
||||
{
|
||||
var path = Path.GetFullPath("./Storage/fortunes");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var rawFortunes= File.ReadAllText(path);
|
||||
var rawFortunes = File.ReadAllText(path);
|
||||
fortuneArray = rawFortunes.Split("%");
|
||||
totalFortunes = fortuneArray.Length;
|
||||
rnd = new Random();
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
class LevelCalc
|
||||
internal class LevelCalc
|
||||
{
|
||||
private static int GetExperienceAtLevel(int level)
|
||||
{
|
||||
double total = 0;
|
||||
for (int i = 1; i < level; i++)
|
||||
{
|
||||
for (var i = 1; i < level; i++)
|
||||
total += Math.Floor(i + 300 * Math.Pow(2, i / 7.0));
|
||||
}
|
||||
|
||||
return (int)Math.Floor(total / 16);
|
||||
return (int) Math.Floor(total / 16);
|
||||
}
|
||||
|
||||
public static int GetLevelAtExperience(int experience)
|
||||
|
@ -22,10 +18,8 @@ namespace Geekbot.net.Lib
|
|||
int index;
|
||||
|
||||
for (index = 0; index < 120; index++)
|
||||
{
|
||||
if (GetExperienceAtLevel(index + 1) > experience)
|
||||
break;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.WebSocket;
|
||||
using StackExchange.Redis;
|
||||
|
||||
|
@ -7,7 +6,6 @@ namespace Geekbot.net.Lib
|
|||
{
|
||||
public class StatsRecorder
|
||||
{
|
||||
|
||||
private readonly SocketMessage message;
|
||||
private readonly IDatabase redis;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using StackExchange.Redis;
|
||||
|
||||
|
@ -8,14 +9,16 @@ namespace Geekbot.net.Modules
|
|||
public class AdminCmd : ModuleBase
|
||||
{
|
||||
private readonly IDatabase redis;
|
||||
|
||||
public AdminCmd(IDatabase redis)
|
||||
{
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
[RequireUserPermission(Discord.GuildPermission.Administrator)]
|
||||
[Command("welcome", RunMode = RunMode.Async), Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
|
||||
public async Task SetWelcomeMessage([Remainder, Summary("The message")] string welcomeMessage)
|
||||
[RequireUserPermission(GuildPermission.Administrator)]
|
||||
[Command("welcome", RunMode = RunMode.Async)]
|
||||
[Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
|
||||
public async Task SetWelcomeMessage([Remainder] [Summary("message")] string welcomeMessage)
|
||||
{
|
||||
var key = Context.Guild.Id + "-welcomeMsg";
|
||||
redis.StringSet(key, welcomeMessage);
|
||||
|
@ -24,7 +27,8 @@ namespace Geekbot.net.Modules
|
|||
formatedMessage);
|
||||
}
|
||||
|
||||
[Command("youtubekey", RunMode = RunMode.Async), Summary("Set the youtube api key")]
|
||||
[Command("youtubekey", RunMode = RunMode.Async)]
|
||||
[Summary("Set the youtube api key")]
|
||||
public async Task SetYoutubeKey([Summary("API Key")] string key)
|
||||
{
|
||||
var botOwner = redis.StringGet("botOwner");
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using RestSharp;
|
||||
|
||||
|
@ -7,17 +6,15 @@ namespace Geekbot.net.Modules
|
|||
{
|
||||
public class Cat : ModuleBase
|
||||
{
|
||||
[Command("cat", RunMode = RunMode.Async), Summary("Return a random image of a cat.")]
|
||||
[Command("cat", RunMode = RunMode.Async)]
|
||||
[Summary("Return a random image of a cat.")]
|
||||
public async Task Say()
|
||||
{
|
||||
var catClient = new RestClient("http://random.cat");
|
||||
var request = new RestRequest("meow.php", Method.GET);
|
||||
|
||||
catClient.ExecuteAsync<CatResponse>(request, async response => {
|
||||
await ReplyAsync(response.Data.file);
|
||||
});
|
||||
catClient.ExecuteAsync<CatResponse>(request, async response => { await ReplyAsync(response.Data.file); });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class CatResponse
|
||||
|
|
|
@ -9,19 +9,22 @@ namespace Geekbot.net.Modules
|
|||
{
|
||||
public class CheckEm : ModuleBase
|
||||
{
|
||||
private readonly Random rnd;
|
||||
private readonly ICheckEmImageProvider checkEmImages;
|
||||
private readonly Random rnd;
|
||||
|
||||
public CheckEm(Random RandomClient, ICheckEmImageProvider checkEmImages)
|
||||
{
|
||||
this.rnd = RandomClient;
|
||||
rnd = RandomClient;
|
||||
this.checkEmImages = checkEmImages;
|
||||
}
|
||||
[Command("checkem", RunMode = RunMode.Async), Summary("Check for dubs")]
|
||||
|
||||
[Command("checkem", RunMode = RunMode.Async)]
|
||||
[Summary("Check for dubs")]
|
||||
public async Task MuhDubs()
|
||||
{
|
||||
try
|
||||
{
|
||||
int number = rnd.Next(10000000, 99999999);
|
||||
var number = rnd.Next(10000000, 99999999);
|
||||
var dubtriqua = "";
|
||||
|
||||
var ns = GetIntArray(number);
|
||||
|
@ -33,19 +36,15 @@ namespace Geekbot.net.Modules
|
|||
{
|
||||
dubtriqua = "TRIPS";
|
||||
if (ns[5] == ns[4])
|
||||
{
|
||||
dubtriqua = "QUADS";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"Check em {Context.User.Mention}");
|
||||
sb.AppendLine($"**{number}**");
|
||||
if (!string.IsNullOrEmpty(dubtriqua))
|
||||
{
|
||||
sb.AppendLine($":tada: {dubtriqua} :tada:");
|
||||
}
|
||||
sb.AppendLine(checkEmImages.GetRandomCheckEmPic());
|
||||
|
||||
await ReplyAsync(sb.ToString());
|
||||
|
@ -54,12 +53,11 @@ namespace Geekbot.net.Modules
|
|||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int[] GetIntArray(int num)
|
||||
{
|
||||
List<int> listOfInts = new List<int>();
|
||||
var listOfInts = new List<int>();
|
||||
while (num > 0)
|
||||
{
|
||||
listOfInts.Add(num % 10);
|
||||
|
|
|
@ -7,13 +7,15 @@ namespace Geekbot.net.Modules
|
|||
public class Choose : ModuleBase
|
||||
{
|
||||
private readonly Random rnd;
|
||||
|
||||
public Choose(Random RandomClient)
|
||||
{
|
||||
rnd = RandomClient;
|
||||
}
|
||||
|
||||
[Command("choose", RunMode = RunMode.Async), Summary("Let the bot make a choice for you.")]
|
||||
public async Task Command([Remainder, Summary("The choices, sepperated by a ;")] string choices)
|
||||
[Command("choose", RunMode = RunMode.Async)]
|
||||
[Summary("Seperate options with a semicolon.")]
|
||||
public async Task Command([Remainder] [Summary("option1;option2")] string choices)
|
||||
{
|
||||
var choicesArray = choices.Split(';');
|
||||
var choice = rnd.Next(choicesArray.Length);
|
||||
|
|
|
@ -9,13 +9,15 @@ namespace Geekbot.net.Modules
|
|||
public class Counters : ModuleBase
|
||||
{
|
||||
private readonly IDatabase redis;
|
||||
|
||||
public Counters(IDatabase redis)
|
||||
{
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
[Command("good", RunMode = RunMode.Async), Summary("Increase Someones Karma")]
|
||||
public async Task Good([Summary("The someone")] IUser user)
|
||||
[Command("good", RunMode = RunMode.Async)]
|
||||
[Summary("Increase Someones Karma")]
|
||||
public async Task Good([Summary("@someone")] IUser user)
|
||||
{
|
||||
var lastKarma = GetLastKarma();
|
||||
if (user.Id == Context.User.Id)
|
||||
|
@ -24,12 +26,13 @@ namespace Geekbot.net.Modules
|
|||
}
|
||||
else if (lastKarma > GetUnixTimestamp())
|
||||
{
|
||||
await ReplyAsync($"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can give karma again...");
|
||||
await ReplyAsync(
|
||||
$"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can give karma again...");
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = Context.Guild.Id + "-" + user.Id + "-karma";
|
||||
var badJokes = (int)redis.StringGet(key);
|
||||
var badJokes = (int) redis.StringGet(key);
|
||||
var newBadJokes = badJokes + 1;
|
||||
redis.StringSet(key, newBadJokes.ToString());
|
||||
var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout";
|
||||
|
@ -44,13 +47,14 @@ namespace Geekbot.net.Modules
|
|||
eb.Title = "Karma Increased";
|
||||
eb.AddInlineField("By", Context.User.Username);
|
||||
eb.AddInlineField("amount", "+1");
|
||||
eb.AddInlineField("Current Karma",newBadJokes);
|
||||
eb.AddInlineField("Current Karma", newBadJokes);
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
}
|
||||
|
||||
[Command("bad", RunMode = RunMode.Async), Summary("Decrease Someones Karma")]
|
||||
public async Task Bad([Summary("The someone")] IUser user)
|
||||
[Command("bad", RunMode = RunMode.Async)]
|
||||
[Summary("Decrease Someones Karma")]
|
||||
public async Task Bad([Summary("@someone")] IUser user)
|
||||
{
|
||||
var lastKarma = GetLastKarma();
|
||||
if (user.Id == Context.User.Id)
|
||||
|
@ -59,12 +63,13 @@ namespace Geekbot.net.Modules
|
|||
}
|
||||
else if (lastKarma > GetUnixTimestamp())
|
||||
{
|
||||
await ReplyAsync($"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can take karma again...");
|
||||
await ReplyAsync(
|
||||
$"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can take karma again...");
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = Context.Guild.Id + "-" + user.Id + "-karma";
|
||||
var badJokes = (int)redis.StringGet(key);
|
||||
var badJokes = (int) redis.StringGet(key);
|
||||
var newBadJokes = badJokes - 1;
|
||||
redis.StringSet(key, newBadJokes.ToString());
|
||||
var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout";
|
||||
|
@ -79,7 +84,7 @@ namespace Geekbot.net.Modules
|
|||
eb.Title = "Karma Decreased";
|
||||
eb.AddInlineField("By", Context.User.Username);
|
||||
eb.AddInlineField("amount", "-1");
|
||||
eb.AddInlineField("Current Karma",newBadJokes);
|
||||
eb.AddInlineField("Current Karma", newBadJokes);
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
}
|
||||
|
@ -89,27 +94,25 @@ namespace Geekbot.net.Modules
|
|||
var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout";
|
||||
var redisReturn = redis.StringGet(lastKey);
|
||||
if (!int.TryParse(redisReturn.ToString(), out var i))
|
||||
{
|
||||
i = GetUnixTimestamp();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
private int GetNewLastKarma()
|
||||
{
|
||||
var timeout = TimeSpan.FromMinutes(3);
|
||||
return (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).Add(timeout)).TotalSeconds;
|
||||
return (int) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).Add(timeout).TotalSeconds;
|
||||
}
|
||||
|
||||
private int GetUnixTimestamp()
|
||||
{
|
||||
return (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
return (int) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
}
|
||||
|
||||
private string GetTimeLeft(int time)
|
||||
{
|
||||
DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,DateTimeKind.Utc);
|
||||
dtDateTime = dtDateTime.AddSeconds( time ).ToLocalTime();
|
||||
var dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
dtDateTime = dtDateTime.AddSeconds(time).ToLocalTime();
|
||||
var dt = dtDateTime.Subtract(DateTime.Now);
|
||||
return $"{dt.Minutes} Minutes and {dt.Seconds} Seconds";
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Dice : ModuleBase
|
||||
{
|
||||
private readonly Random rnd;
|
||||
|
||||
public Dice(Random RandomClient)
|
||||
{
|
||||
rnd = RandomClient;
|
||||
}
|
||||
|
||||
[Command("dice", RunMode = RunMode.Async), Summary("Roll a dice.")]
|
||||
public async Task RollCommand([Remainder, Summary("1d20, 1d6, 2d3, etc...")] string diceType = "1d6")
|
||||
[Command("dice", RunMode = RunMode.Async)]
|
||||
[Summary("Roll a dice.")]
|
||||
public async Task RollCommand([Remainder] [Summary("diceType")] string diceType = "1d6")
|
||||
{
|
||||
var dice = diceType.Split("d");
|
||||
|
||||
|
@ -45,9 +45,7 @@ namespace Geekbot.net.Modules
|
|||
eb.WithColor(new Color(133, 189, 219));
|
||||
eb.Title = $":game_die: Dice Roll - Type {diceType} :game_die:";
|
||||
for (var i = 0; i < times; i++)
|
||||
{
|
||||
eb.AddInlineField($"Dice {i+1}", rnd.Next(1, max));
|
||||
}
|
||||
eb.AddInlineField($"Dice {i + 1}", rnd.Next(1, max));
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,15 @@ namespace Geekbot.net.Modules
|
|||
{
|
||||
public class Dog : ModuleBase
|
||||
{
|
||||
[Command("dog", RunMode = RunMode.Async), Summary("Return a random image of a dog.")]
|
||||
[Command("dog", RunMode = RunMode.Async)]
|
||||
[Summary("Return a random image of a dog.")]
|
||||
public async Task Say()
|
||||
{
|
||||
var dogClient = new RestClient("http://random.dog");
|
||||
var request = new RestRequest("woof.json", Method.GET);
|
||||
Console.WriteLine(dogClient.BaseUrl);
|
||||
|
||||
dogClient.ExecuteAsync<DogResponse>(request, async response => {
|
||||
await ReplyAsync(response.Data.url);
|
||||
});
|
||||
dogClient.ExecuteAsync<DogResponse>(request, async response => { await ReplyAsync(response.Data.url); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,14 +8,18 @@ namespace Geekbot.net.Modules
|
|||
public class EightBall : ModuleBase
|
||||
{
|
||||
private readonly Random rnd;
|
||||
|
||||
public EightBall(Random RandomClient)
|
||||
{
|
||||
rnd = RandomClient;
|
||||
}
|
||||
[Command("8ball", RunMode = RunMode.Async), Summary("Ask 8Ball a Question.")]
|
||||
public async Task Ball([Remainder, Summary("The Question")] string echo)
|
||||
|
||||
[Command("8ball", RunMode = RunMode.Async)]
|
||||
[Summary("Ask 8Ball a Question.")]
|
||||
public async Task Ball([Remainder] [Summary("Question")] string echo)
|
||||
{
|
||||
var replies = new List<string>
|
||||
{
|
||||
var replies = new List<string> {
|
||||
"It is certain",
|
||||
"It is decidedly so",
|
||||
"Without a doubt",
|
||||
|
@ -35,7 +39,8 @@ namespace Geekbot.net.Modules
|
|||
"My reply is no",
|
||||
"My sources say no",
|
||||
"Outlook not so good",
|
||||
"Very doubtful"};
|
||||
"Very doubtful"
|
||||
};
|
||||
|
||||
var answer = rnd.Next(replies.Count);
|
||||
await ReplyAsync(replies[answer]);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
|
@ -8,12 +7,14 @@ namespace Geekbot.net.Modules
|
|||
public class Fortune : ModuleBase
|
||||
{
|
||||
private readonly IFortunesProvider fortunes;
|
||||
|
||||
public Fortune(IFortunesProvider fortunes)
|
||||
{
|
||||
this.fortunes = fortunes;
|
||||
}
|
||||
|
||||
[Command("fortune", RunMode = RunMode.Async), Summary("Get a random fortune")]
|
||||
[Command("fortune", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random fortune")]
|
||||
public async Task GetAFortune()
|
||||
{
|
||||
await ReplyAsync(fortunes.GetRandomFortune());
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord;
|
||||
using Geekbot.net.Lib;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
|
@ -11,12 +11,14 @@ namespace Geekbot.net.Modules
|
|||
public class GuildInfo : ModuleBase
|
||||
{
|
||||
private readonly IDatabase redis;
|
||||
|
||||
public GuildInfo(IDatabase redis)
|
||||
{
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
[Command("serverstats", RunMode = RunMode.Async), Summary("Show some info about the bot.")]
|
||||
[Command("serverstats", RunMode = RunMode.Async)]
|
||||
[Summary("Show some info about the bot.")]
|
||||
public async Task getInfo()
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
|
@ -29,7 +31,7 @@ namespace Geekbot.net.Modules
|
|||
var age = Math.Floor((DateTime.Now - created).TotalDays);
|
||||
|
||||
var messages = redis.StringGet($"{Context.Guild.Id}-messages");
|
||||
var level = LevelCalc.GetLevelAtExperience((int)messages);
|
||||
var level = LevelCalc.GetLevelAtExperience((int) messages);
|
||||
|
||||
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
||||
eb.AddInlineField("Level", level)
|
||||
|
@ -40,7 +42,7 @@ namespace Geekbot.net.Modules
|
|||
|
||||
public static string FirstCharToUpper(string input)
|
||||
{
|
||||
if (String.IsNullOrEmpty(input))
|
||||
if (string.IsNullOrEmpty(input))
|
||||
throw new ArgumentException("ARGH!");
|
||||
return input.First().ToString().ToUpper() + input.Substring(1);
|
||||
}
|
||||
|
|
|
@ -1,27 +1,48 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Help : ModuleBase
|
||||
{
|
||||
[Command("help", RunMode = RunMode.Async), Summary("List all Commands")]
|
||||
private readonly CommandService commands;
|
||||
|
||||
public Help(CommandService commands)
|
||||
{
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
[Command("help", RunMode = RunMode.Async)]
|
||||
[Summary("List all Commands")]
|
||||
public async Task GetHelp()
|
||||
{
|
||||
var commands = new CommandService();
|
||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||
var cmdList = commands.Commands;
|
||||
var reply = "**Geekbot Command list**\r\n";
|
||||
foreach (var cmd in cmdList)
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("```");
|
||||
sb.AppendLine("**Geekbot Command list**");
|
||||
sb.AppendLine("");
|
||||
sb.AppendLine(tp("Name", 15) + tp("Parameters", 19) + "Description");
|
||||
foreach (var cmd in commands.Commands)
|
||||
{
|
||||
var param = string.Join(", !",cmd.Aliases);
|
||||
var param = string.Join(", !", cmd.Aliases);
|
||||
if (!param.Contains("admin"))
|
||||
if (cmd.Parameters.Any())
|
||||
sb.AppendLine(tp(param, 15) +
|
||||
tp(string.Join(",", cmd.Parameters.Select(e => e.Summary)), 19) +
|
||||
cmd.Summary);
|
||||
else
|
||||
sb.AppendLine(tp(param, 34) + cmd.Summary);
|
||||
}
|
||||
sb.AppendLine("```");
|
||||
var dm = await Context.User.GetOrCreateDMChannelAsync();
|
||||
await dm.SendMessageAsync(sb.ToString());
|
||||
}
|
||||
|
||||
// Table Padding, short function name because of many usages
|
||||
private string tp(string text, int shouldHave)
|
||||
{
|
||||
reply = reply + $"**{cmd.Name}** (!{param}) - {cmd.Summary}\r\n";
|
||||
}
|
||||
}
|
||||
await ReplyAsync(reply);
|
||||
return text.PadRight(shouldHave);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,12 +8,14 @@ namespace Geekbot.net.Modules
|
|||
public class Info : ModuleBase
|
||||
{
|
||||
private readonly IDatabase redis;
|
||||
|
||||
public Info(IDatabase redis)
|
||||
{
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
[Command("info", RunMode = RunMode.Async), Summary("Get Information about the bot")]
|
||||
[Command("info", RunMode = RunMode.Async)]
|
||||
[Summary("Get Information about the bot")]
|
||||
public async Task BotInfo()
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Ping : ModuleBase
|
||||
{
|
||||
[Command("👀", RunMode = RunMode.Async), Summary("Look at the bot.")]
|
||||
[Command("👀", RunMode = RunMode.Async)]
|
||||
[Summary("Look at the bot.")]
|
||||
public async Task Eyes()
|
||||
{
|
||||
await ReplyAsync("S... Stop looking at me... baka!");
|
||||
|
|
|
@ -9,14 +9,16 @@ namespace Geekbot.net.Modules
|
|||
{
|
||||
private readonly IDatabase redis;
|
||||
private readonly Random rnd;
|
||||
|
||||
public Roll(IDatabase redis, Random RandomClient)
|
||||
{
|
||||
this.redis = redis;
|
||||
this.rnd = RandomClient;
|
||||
rnd = RandomClient;
|
||||
}
|
||||
|
||||
[Command("roll", RunMode = RunMode.Async), Summary("Roll a number between 1 and 100.")]
|
||||
public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing")
|
||||
[Command("roll", RunMode = RunMode.Async)]
|
||||
[Summary("Roll a number between 1 and 100.")]
|
||||
public async Task RollCommand([Remainder] [Summary("stuff...")] string stuff = "nothing")
|
||||
{
|
||||
var number = rnd.Next(1, 100);
|
||||
var guess = 1000;
|
||||
|
@ -28,7 +30,7 @@ namespace Geekbot.net.Modules
|
|||
{
|
||||
await ReplyAsync($"Congratulations {Context.User.Username}, your guess was correct!");
|
||||
var key = $"{Context.Guild.Id}-{Context.User.Id}-correctRolls";
|
||||
var messages = (int)redis.StringGet(key);
|
||||
var messages = (int) redis.StringGet(key);
|
||||
redis.StringSet(key, (messages + 1).ToString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Say : ModuleBase
|
||||
{
|
||||
[RequireUserPermission(Discord.GuildPermission.Administrator)]
|
||||
[Command("say", RunMode = RunMode.Async), Summary("Say Something.")]
|
||||
public async Task Echo([Remainder, Summary("What?")] string echo)
|
||||
[RequireUserPermission(GuildPermission.Administrator)]
|
||||
[Command("say", RunMode = RunMode.Async)]
|
||||
[Summary("Say Something.")]
|
||||
public async Task Echo([Remainder] [Summary("What?")] string echo)
|
||||
{
|
||||
await Context.Message.DeleteAsync();
|
||||
await ReplyAsync(echo);
|
||||
|
|
|
@ -8,28 +8,25 @@ namespace Geekbot.net.Modules
|
|||
{
|
||||
public class Ship : ModuleBase
|
||||
{
|
||||
|
||||
private readonly IDatabase redis;
|
||||
private readonly Random rnd;
|
||||
|
||||
public Ship(IDatabase redis, Random RandomClient)
|
||||
{
|
||||
this.redis = redis;
|
||||
this.rnd = RandomClient;
|
||||
rnd = RandomClient;
|
||||
}
|
||||
|
||||
[Command("Ship", RunMode = RunMode.Async), Summary("Ask the Shipping meter")]
|
||||
public async Task Command([Summary("User 1")] IUser user1, [Summary("User 2")] IUser user2)
|
||||
[Command("Ship", RunMode = RunMode.Async)]
|
||||
[Summary("Ask the Shipping meter")]
|
||||
public async Task Command([Summary("@User1")] IUser user1, [Summary("@User2")] IUser user2)
|
||||
{
|
||||
// Create a String
|
||||
var dbstring = "";
|
||||
if (user1.Id > user2.Id)
|
||||
{
|
||||
dbstring = $"{user1.Id}-{user2.Id}";
|
||||
}
|
||||
else
|
||||
{
|
||||
dbstring = $"{user2.Id}-{user1.Id}";
|
||||
}
|
||||
dbstring = $"{Context.Guild.Id}-{dbstring}";
|
||||
Console.WriteLine(dbstring);
|
||||
|
||||
|
@ -54,21 +51,15 @@ namespace Geekbot.net.Modules
|
|||
private string DeterminateSuccess(int rate)
|
||||
{
|
||||
if (rate < 20)
|
||||
{
|
||||
return "Not gonna happen";
|
||||
} if (rate >= 20 && rate < 40)
|
||||
{
|
||||
if (rate >= 20 && rate < 40)
|
||||
return "Not such a good idea";
|
||||
} if (rate >= 40 && rate < 60)
|
||||
{
|
||||
if (rate >= 40 && rate < 60)
|
||||
return "There might be a chance";
|
||||
} if (rate >= 60 && rate < 80)
|
||||
{
|
||||
if (rate >= 60 && rate < 80)
|
||||
return "Almost a match, but could work";
|
||||
} if (rate >= 80)
|
||||
{
|
||||
if (rate >= 80)
|
||||
return "It's a match";
|
||||
}
|
||||
return "a";
|
||||
}
|
||||
|
||||
|
@ -77,20 +68,17 @@ namespace Geekbot.net.Modules
|
|||
var amount = Math.Floor(decimal.Floor(rate / 10));
|
||||
Console.WriteLine(amount);
|
||||
var blocks = "";
|
||||
for(int i = 1; i <= 10; i++)
|
||||
{
|
||||
if(i <= amount)
|
||||
for (var i = 1; i <= 10; i++)
|
||||
if (i <= amount)
|
||||
{
|
||||
blocks = blocks + ":white_medium_small_square:";
|
||||
if(i == amount)
|
||||
{
|
||||
if (i == amount)
|
||||
blocks = blocks + $" {rate}% ";
|
||||
}
|
||||
} else
|
||||
else
|
||||
{
|
||||
blocks = blocks + ":black_medium_small_square:";
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
@ -13,27 +13,28 @@ namespace Geekbot.net.Modules
|
|||
public class UserInfo : ModuleBase
|
||||
{
|
||||
private readonly IDatabase redis;
|
||||
|
||||
public UserInfo(IDatabase redis)
|
||||
{
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
[Alias("stats")]
|
||||
[Command("user", RunMode = RunMode.Async), Summary("Get information about this user")]
|
||||
public async Task User([Summary("The (optional) user to get info for")] IUser user = null)
|
||||
[Command("user", RunMode = RunMode.Async)]
|
||||
[Summary("Get information about this user")]
|
||||
public async Task User([Summary("@someone")] IUser user = null)
|
||||
{
|
||||
var userInfo = user ?? Context.Message.Author;
|
||||
|
||||
var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays);
|
||||
|
||||
var key = Context.Guild.Id + "-" + userInfo.Id;
|
||||
var messages = (int)redis.StringGet(key + "-messages");
|
||||
var messages = (int) redis.StringGet(key + "-messages");
|
||||
var level = LevelCalc.GetLevelAtExperience(messages);
|
||||
|
||||
var guildKey = Context.Guild.Id.ToString();
|
||||
var guildMessages = (int)redis.StringGet(guildKey + "-messages");
|
||||
var guildMessages = (int) redis.StringGet(guildKey + "-messages");
|
||||
|
||||
var percent = Math.Round((double)(100 * messages) / guildMessages, 2);
|
||||
var percent = Math.Round((double) (100 * messages) / guildMessages, 2);
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
|
@ -42,56 +43,53 @@ namespace Geekbot.net.Modules
|
|||
|
||||
eb.WithColor(new Color(221, 255, 119));
|
||||
|
||||
eb.AddField("Discordian Since", $"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)");
|
||||
eb.AddField("Discordian Since",
|
||||
$"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)");
|
||||
eb.AddInlineField("Level", level)
|
||||
.AddInlineField("Messages Sent", messages)
|
||||
.AddInlineField("Server Total", $"{percent}%");
|
||||
|
||||
var karma = redis.StringGet(key + "-karma");
|
||||
if (!karma.IsNullOrEmpty)
|
||||
{
|
||||
eb.AddInlineField("Karma", karma);
|
||||
}
|
||||
|
||||
var correctRolls = redis.StringGet($"{Context.Guild.Id}-{userInfo.Id}-correctRolls");
|
||||
if (!correctRolls.IsNullOrEmpty)
|
||||
{
|
||||
eb.AddInlineField("Guessed Rolls", correctRolls);
|
||||
}
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
|
||||
[Alias("highscore")]
|
||||
[Command("rank", RunMode = RunMode.Async), Summary("get user top 10")]
|
||||
[Command("rank", RunMode = RunMode.Async)]
|
||||
[Summary("get user top 10")]
|
||||
public async Task Rank()
|
||||
{
|
||||
await ReplyAsync("this will take a moment...");
|
||||
var guildKey = Context.Guild.Id.ToString();
|
||||
var guildMessages = (int)redis.StringGet(guildKey + "-messages");
|
||||
var guildMessages = (int) redis.StringGet(guildKey + "-messages");
|
||||
var allGuildUsers = await Context.Guild.GetUsersAsync();
|
||||
var unsortedDict = new Dictionary<string, int>();
|
||||
foreach(var user in allGuildUsers)
|
||||
foreach (var user in allGuildUsers)
|
||||
{
|
||||
var key = Context.Guild.Id + "-" + user.Id;
|
||||
var messages = (int)redis.StringGet(key + "-messages");
|
||||
if(messages > 0) {
|
||||
var messages = (int) redis.StringGet(key + "-messages");
|
||||
if (messages > 0)
|
||||
unsortedDict.Add($"{user.Username}#{user.Discriminator}", messages);
|
||||
}
|
||||
}
|
||||
var sortedDict = unsortedDict.OrderByDescending(x => x.Value);
|
||||
var reply = new StringBuilder();
|
||||
reply.AppendLine($"Total Messages on {Context.Guild.Name}: {guildMessages}");
|
||||
var count = 1;
|
||||
foreach(KeyValuePair<string, int> entry in sortedDict)
|
||||
foreach (var entry in sortedDict)
|
||||
if (count < 11)
|
||||
{
|
||||
if(count < 11){
|
||||
var percent = Math.Round((double)(100 * entry.Value) / guildMessages, 2);
|
||||
var percent = Math.Round((double) (100 * entry.Value) / guildMessages, 2);
|
||||
reply.AppendLine($"#{count} - **{entry.Key}** - {percent}% of total - {entry.Value} messages");
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
await ReplyAsync(reply.ToString());
|
||||
}
|
||||
|
|
|
@ -10,13 +10,15 @@ namespace Geekbot.net.Modules
|
|||
public class Youtube : ModuleBase
|
||||
{
|
||||
private readonly IDatabase redis;
|
||||
|
||||
public Youtube(IDatabase redis)
|
||||
{
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
[Command("yt", RunMode = RunMode.Async), Summary("Search for something on youtube.")]
|
||||
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
||||
[Command("yt", RunMode = RunMode.Async)]
|
||||
[Summary("Search for something on youtube.")]
|
||||
public async Task Yt([Remainder] [Summary("Title")] string searchQuery)
|
||||
{
|
||||
var key = redis.StringGet("youtubeKey");
|
||||
if (key.IsNullOrEmpty)
|
||||
|
@ -27,10 +29,10 @@ namespace Geekbot.net.Modules
|
|||
|
||||
try
|
||||
{
|
||||
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||
var youtubeService = new YouTubeService(new BaseClientService.Initializer
|
||||
{
|
||||
ApiKey = key.ToString(),
|
||||
ApplicationName = this.GetType().ToString()
|
||||
ApplicationName = GetType().ToString()
|
||||
});
|
||||
|
||||
var searchListRequest = youtubeService.Search.List("snippet");
|
||||
|
@ -49,7 +51,8 @@ namespace Geekbot.net.Modules
|
|||
await ReplyAsync("Something went wrong... informing my senpai...");
|
||||
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.StringGet("botOwner"))).Result;
|
||||
var dm = await botOwner.GetOrCreateDMChannelAsync();
|
||||
await dm.SendMessageAsync($"Something went wrong while getting a video from youtube:\r\n```\r\n{e.Message}\r\n```");
|
||||
await dm.SendMessageAsync(
|
||||
$"Something went wrong while getting a video from youtube:\r\n```\r\n{e.Message}\r\n```");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,25 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Modules;
|
||||
using RestSharp;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net
|
||||
{
|
||||
class Program
|
||||
internal class Program
|
||||
{
|
||||
private CommandService commands;
|
||||
private DiscordSocketClient client;
|
||||
private CommandService commands;
|
||||
private IDatabase redis;
|
||||
private RedisValue token;
|
||||
private IServiceCollection services;
|
||||
private IServiceProvider servicesProvider;
|
||||
private RedisValue token;
|
||||
|
||||
private static void Main(string[] args)
|
||||
private static void Main()
|
||||
{
|
||||
Console.WriteLine(@" ____ _____ _____ _ ______ ___ _____");
|
||||
Console.WriteLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
||||
|
@ -71,10 +66,10 @@ namespace Geekbot.net
|
|||
var fortunes = new FortunesProvider();
|
||||
var checkEmImages = new CheckEmImageProvider();
|
||||
var RandomClient = new Random();
|
||||
services.AddSingleton(redis);
|
||||
services.AddSingleton(RandomClient);
|
||||
services.AddSingleton<IFortunesProvider>(fortunes);
|
||||
services.AddSingleton<ICheckEmImageProvider>(checkEmImages);
|
||||
services.AddSingleton(RandomClient);
|
||||
services.AddSingleton(redis);
|
||||
|
||||
Console.WriteLine("* Connecting to Discord");
|
||||
|
||||
|
@ -101,6 +96,7 @@ namespace Geekbot.net
|
|||
client.MessageReceived += HandleMessageReceived;
|
||||
client.UserJoined += HandleUserJoined;
|
||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||
services.AddSingleton(commands);
|
||||
servicesProvider = services.BuildServiceProvider();
|
||||
|
||||
Console.WriteLine("* Done and ready for use\n");
|
||||
|
@ -116,9 +112,7 @@ namespace Geekbot.net
|
|||
public async Task<bool> isConnected()
|
||||
{
|
||||
while (!client.ConnectionState.Equals(ConnectionState.Connected))
|
||||
{
|
||||
await Task.Delay(25);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -127,7 +121,7 @@ namespace Geekbot.net
|
|||
var message = messageParam as SocketUserMessage;
|
||||
if (message == null) return;
|
||||
if (message.Author.IsBot) return;
|
||||
int argPos = 0;
|
||||
var argPos = 0;
|
||||
var lowCaseMsg = message.ToString().ToLower();
|
||||
if (lowCaseMsg.StartsWith("ping"))
|
||||
{
|
||||
|
@ -139,7 +133,8 @@ namespace Geekbot.net
|
|||
await message.Channel.SendMessageAsync("hui!!!");
|
||||
return;
|
||||
}
|
||||
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);
|
||||
Task.Run(async () => await commands.ExecuteAsync(context, argPos, servicesProvider));
|
||||
}
|
||||
|
@ -149,13 +144,14 @@ namespace Geekbot.net
|
|||
var message = messsageParam;
|
||||
if (message == null) return;
|
||||
|
||||
var channel = (SocketGuildChannel)message.Channel;
|
||||
|
||||
Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content);
|
||||
|
||||
var statsRecorder = new StatsRecorder(message, redis);
|
||||
Task.Run(async () => await statsRecorder.UpdateUserRecordAsync());
|
||||
Task.Run(async () => await statsRecorder.UpdateGuildRecordAsync());
|
||||
|
||||
if (message.Author.Id == client.CurrentUser.Id) return;
|
||||
var channel = (SocketGuildChannel) message.Channel;
|
||||
Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " +
|
||||
message.Content);
|
||||
}
|
||||
|
||||
public async Task HandleUserJoined(SocketGuildUser user)
|
||||
|
|
Loading…
Reference in a new issue