Embeds, Cleanup and Improvements to Roll, Userinfo the init process

This commit is contained in:
Runebaas 2017-04-17 23:58:43 +02:00
parent 6d5c6f2ea8
commit 735a4a81d4
5 changed files with 65 additions and 33 deletions

View file

@ -18,10 +18,6 @@ namespace Geekbot.net.Lib
// { // {
// get // get
// { // {
// if (_instance.IsValueCreated)
// {
// return _instance.Value;
// }
// lock (ThreadLock) // lock (ThreadLock)
// { // {
// if (Client == null) // if (Client == null)

View file

@ -0,0 +1,21 @@
using System;
using System.Threading.Tasks;
using Discord.Commands;
using Discord;
namespace Geekbot.net.Modules
{
public class Info : ModuleBase
{
[Command("info"), Summary("Show some info about the bot.")]
public async Task getInfo()
{
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
.WithIconUrl(Context.User.GetAvatarUrl())
.WithName(Context.User.Username));
eb.AddField("Test", "Some testing stuff here...");
await ReplyAsync("", false, eb.Build());
}
}
}

View file

@ -7,12 +7,25 @@ namespace Geekbot.net.Modules
public class Roll : ModuleBase public class Roll : ModuleBase
{ {
[Command("roll"), Summary("Roll a number between 1 and 100.")] [Command("roll"), Summary("Roll a number between 1 and 100.")]
public async Task RollCommand() public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing")
{ {
var rnd = new Random(); var rnd = new Random();
var number = rnd.Next(1, 100); var number = rnd.Next(1, 100);
var guess = 1000;
int.TryParse(stuff, out guess);
if (guess <= 100 && guess > 0)
{
await ReplyAsync($"{Context.Message.Author.Mention} you rolled {number}, your guess was {guess}");
if (guess == number)
{
await ReplyAsync($"Congratulations {Context.User.Username}, your guess was correct!");
}
}
else
{
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
} }
}
[Command("dice"), Summary("Roll a dice")] [Command("dice"), Summary("Roll a dice")]
public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6) public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6)

View file

@ -21,34 +21,25 @@ namespace Geekbot.net.Modules
var messages = (int)redis.StringGet(key + "-messages"); var messages = (int)redis.StringGet(key + "-messages");
var level = GetLevelAtExperience(messages); var level = GetLevelAtExperience(messages);
var reply = ""; var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
.WithIconUrl(userInfo.GetAvatarUrl())
.WithName(userInfo.Username));
if (Context.Message.Author.Id == userInfo.Id) eb.AddField("Discordian Since", $"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)");
eb.AddField("Level", level);
eb.AddField("Messages Sent", messages);
var karma = redis.StringGet(key + "-karma");
if (!karma.IsNullOrEmpty)
{ {
reply = reply + $"here are your stats {userInfo.Mention}\r\n"; eb.AddField("Karma", karma);
}
else
{
reply = reply + $"here are {userInfo.Mention}'s stats\r\n";
} }
reply = reply + $"```\r\n"; await ReplyAsync("", false, eb.Build());
reply = reply + $"Discordian Since: {userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)\r\n";
reply = reply + $"Level: {level}\r\n";
reply = reply + $"Messages Sent: {messages}\r\n";
var jokeKarma = redis.StringGet(key + "-karma");
if (!jokeKarma.IsNullOrEmpty)
{
reply = reply + $"Karma: {jokeKarma}\r\n";
} }
reply = reply + $"```"; public async Task GetLevel(string xp)
await ReplyAsync(reply);
}
public async Task GetLevel([Summary("The (optional) user to get info for")] string xp)
{ {
var level = GetLevelAtExperience(int.Parse(xp)); var level = GetLevelAtExperience(int.Parse(xp));
await ReplyAsync(level.ToString()); await ReplyAsync(level.ToString());

View file

@ -12,7 +12,7 @@ namespace Geekbot.net
{ {
class Program class Program
{ {
public CommandService commands; private CommandService commands;
private DiscordSocketClient client; private DiscordSocketClient client;
private DependencyMap map; private DependencyMap map;
private IDatabase redis; private IDatabase redis;
@ -28,7 +28,6 @@ namespace Geekbot.net
Console.WriteLine("Starting..."); Console.WriteLine("Starting...");
//Task.WaitAll(BootTasks.CheckSettingsFile()); //Task.WaitAll(BootTasks.CheckSettingsFile());
Task.WaitAll(new Program().MainAsync()); Task.WaitAll(new Program().MainAsync());
} }
@ -36,8 +35,20 @@ namespace Geekbot.net
{ {
client = new DiscordSocketClient(); client = new DiscordSocketClient();
commands = new CommandService(); commands = new CommandService();
redis = new RedisClient().Client;
const string token = "MTgxMDkyOTgxMDUzNDU2Mzg0.C8_UTw.PvXLAVOTccbrWKLMeyvN9WqRPlU"; var token = redis.StringGet("discordToken");
if (token.IsNullOrEmpty)
{
Console.Write("Your bot Token: ");
var newToken = Console.ReadLine();
redis.StringSet("discordToken", newToken);
token = newToken;
Console.Write("Bot Owner User ID: ");
var ownerId = Console.ReadLine();
redis.StringSet("botOwner", ownerId);
}
map = new DependencyMap(); map = new DependencyMap();
map.Add<ICatClient>(new CatClient()); map.Add<ICatClient>(new CatClient());
@ -90,7 +101,7 @@ namespace Geekbot.net
{ {
var message = messsageParam; var message = messsageParam;
if (message == null) return; if (message == null) return;
if (message.Author.Username.Contains("Geekbot")) return; if (message.Author.Username.Equals(client.CurrentUser.Username)) return;
var channel = (SocketGuildChannel)message.Channel; var channel = (SocketGuildChannel)message.Channel;