Karma, Say, Help

This commit is contained in:
Runebaas 2017-04-17 16:58:48 +02:00
parent 59d0a5e135
commit 6d5c6f2ea8
9 changed files with 139 additions and 45 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
Geekbot.net/bin Geekbot.net/bin
Geekbot.net/obj Geekbot.net/obj
Backup/
.vs/
UpgradeLog.htm

View file

@ -7,23 +7,16 @@ namespace Geekbot.net.Modules
[Group("admin")] [Group("admin")]
public class AdminCmd : ModuleBase public class AdminCmd : ModuleBase
{ {
[RequireUserPermission(Discord.GuildPermission.Administrator)]
[Command("welcome"), Summary("Set a Welcome Message (use '$user' to mention the new joined user).")] [Command("welcome"), Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
public async Task SetWelcomeMessage([Remainder, Summary("The message")] string welcomeMessage) public async Task SetWelcomeMessage([Remainder, Summary("The message")] string welcomeMessage)
{ {
if (Context.Guild.OwnerId.Equals(Context.User.Id)) var redis = new RedisClient().Client;
{ var key = Context.Guild.Id + "-welcomeMsg";
var redis = new RedisClient().Client; redis.StringSet(key, welcomeMessage);
var key = Context.Guild.Id + "-welcome-msg"; var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention);
redis.StringSet(key, welcomeMessage); await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" +
var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention); formatedMessage);
await ReplyAsync("W!elcome message has been changed\r\nHere is an example of how it would look:\r\n" +
formatedMessage);
}
else
{
await ReplyAsync("Sorry, only the Server Owner can do this");
}
} }
} }
} }

View file

@ -0,0 +1,45 @@
using System;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
namespace Geekbot.net.Modules
{
public class Counters : ModuleBase
{
[Command("good"), Summary("Increase Someones Karma")]
public async Task Good([Summary("The someone")] IUser user)
{
if (user.Id == Context.User.Id)
{
await ReplyAsync($"Sorry {Context.User.Username}, but you can't give yourself karma");
}
else
{
var redis = new RedisClient().Client;
var key = Context.Guild.Id + "-" + user.Id + "-karma";
var badJokes = (int)redis.StringGet(key);
redis.StringSet(key, (badJokes + 1).ToString());
await ReplyAsync($"{Context.User.Username} gave {user.Mention} karma");
}
}
[Command("bad"), Summary("Decrease Someones Karma")]
public async Task Bad([Summary("The someone")] IUser user)
{
if (user.Id == Context.User.Id)
{
await ReplyAsync($"Sorry {Context.User.Username}, but you can't lower your own karma");
}
else
{
var redis = new RedisClient().Client;
var key = Context.Guild.Id + "-" + user.Id + "-karma";
var badJokes = (int)redis.StringGet(key);
redis.StringSet(key, (badJokes - 1).ToString());
await ReplyAsync($"{Context.User.Username} lowered {user.Mention}'s karma");
}
}
}
}

View file

@ -0,0 +1,27 @@
using System.Threading.Tasks;
using Discord.Commands;
using System.Reflection;
namespace Geekbot.net.Modules
{
public class Help : ModuleBase
{
[Command("help"), 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 param = string.Join(", !",cmd.Aliases);
if (!param.Contains("admin"))
{
reply = reply + $"**{cmd.Name}** (!{param}) - {cmd.Summary}\r\n";
}
}
await ReplyAsync(reply);
}
}
}

View file

@ -8,13 +8,8 @@ namespace Geekbot.net.Modules
[Command("ping"), Summary("Pong.")] [Command("ping"), Summary("Pong.")]
public async Task Say() public async Task Say()
{ {
await Task.Delay(5000);
await ReplyAsync("Pong"); await ReplyAsync("Pong");
} }
[Command("hui"), Summary("hui!!!.")]
public async Task Hui()
{
await ReplyAsync("hui!!!");
}
} }
} }

View file

@ -14,11 +14,11 @@ namespace Geekbot.net.Modules
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
} }
[Command("dice"), Summary("Roll a number between 1 and 100.")] [Command("dice"), Summary("Roll a dice")]
public async Task DiceCommand() public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6)
{ {
var rnd = new Random(); var rnd = new Random();
var number = rnd.Next(1, 6); var number = rnd.Next(1, max);
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
} }
} }

View file

@ -0,0 +1,16 @@
using System.Threading.Tasks;
using Discord.Commands;
namespace Geekbot.net.Modules
{
public class Say : ModuleBase
{
[RequireUserPermission(Discord.GuildPermission.Administrator)]
[Command("say"), Summary("Say Something.")]
public async Task Echo([Remainder, Summary("What?")] string echo)
{
await Context.Message.DeleteAsync();
await ReplyAsync(echo);
}
}
}

View file

@ -8,7 +8,7 @@ namespace Geekbot.net.Modules
{ {
public class UserInfo : ModuleBase public class UserInfo : ModuleBase
{ {
[Alias("stats", "whois")] [Alias("stats")]
[Command("user"), Summary("Get information about this user")] [Command("user"), Summary("Get information about this user")]
public async Task User([Summary("The (optional) user to get info for")] IUser user = null) public async Task User([Summary("The (optional) user to get info for")] IUser user = null)
{ {
@ -17,8 +17,8 @@ namespace Geekbot.net.Modules
var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays); var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays);
var redis = new RedisClient().Client; var redis = new RedisClient().Client;
var key = Context.Guild.Id + "-" + userInfo.Id + "-messages"; var key = Context.Guild.Id + "-" + userInfo.Id;
var messages = (int)redis.StringGet(key); var messages = (int)redis.StringGet(key + "-messages");
var level = GetLevelAtExperience(messages); var level = GetLevelAtExperience(messages);
var reply = ""; var reply = "";
@ -33,17 +33,21 @@ namespace Geekbot.net.Modules
} }
reply = reply + $"```\r\n"; reply = reply + $"```\r\n";
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 + $"Level: {level}\r\n";
reply = reply + $"Messages Sent: {messages}\r\n"; reply = reply + $"Messages Sent: {messages}\r\n";
reply =
reply + var jokeKarma = redis.StringGet(key + "-karma");
$"Discordian Since: {userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)"; if (!jokeKarma.IsNullOrEmpty)
{
reply = reply + $"Karma: {jokeKarma}\r\n";
}
reply = reply + $"```"; reply = reply + $"```";
await ReplyAsync(reply); await ReplyAsync(reply);
} }
[Command("level"), Summary("Get a level based on a number")]
public async Task GetLevel([Summary("The (optional) user to get info for")] string xp) 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));

View file

@ -12,22 +12,22 @@ namespace Geekbot.net
{ {
class Program class Program
{ {
private CommandService commands; public CommandService commands;
private DiscordSocketClient client; private DiscordSocketClient client;
private DependencyMap map; private DependencyMap map;
private IDatabase redis; private IDatabase redis;
private static void Main(string[] args) private static void Main(string[] args)
{ {
Console.WriteLine(" ____ _____ _____ _ ______ ___ _____"); Console.WriteLine(@" ____ _____ _____ _ ______ ___ _____");
Console.WriteLine(" / ___| ____| ____| |/ / __ ) / _ \\_ _|"); Console.WriteLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
Console.WriteLine("| | _| _| | _| | ' /| _ \\| | | || |"); Console.WriteLine(@"| | _| _| | _| | ' /| _ \| | | || |");
Console.WriteLine("| |_| | |___| |___| . \\| |_) | |_| || |"); Console.WriteLine(@"| |_| | |___| |___| . \| |_) | |_| || |");
Console.WriteLine(" \\____|_____|_____|_|\\_\\____/ \\___/ |_|"); Console.WriteLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
Console.WriteLine("========================================="); Console.WriteLine("=========================================");
Console.WriteLine("Starting..."); Console.WriteLine("Starting...");
// Task.WaitAll(BootTasks.CheckSettingsFile()); //Task.WaitAll(BootTasks.CheckSettingsFile());
Task.WaitAll(new Program().MainAsync()); Task.WaitAll(new Program().MainAsync());
} }
@ -66,13 +66,24 @@ namespace Geekbot.net
var message = messageParam as SocketUserMessage; var message = messageParam as SocketUserMessage;
if (message == null) return; if (message == null) return;
int argPos = 0; int argPos = 0;
if (message.ToString().ToLower().Equals("ping"))
{
await message.Channel.SendMessageAsync("pong");
return;
}
if (message.ToString().ToLower().Equals("hui"))
{
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); var context = new CommandContext(client, message);
var result = await commands.ExecuteAsync(context, argPos, map); commands.ExecuteAsync(context, argPos, map);
if (!result.IsSuccess) //var result = await commands.ExecuteAsync(context, argPos, map);
{ //if (!result.IsSuccess)
await context.Channel.SendMessageAsync(result.ErrorReason); //{
} // await context.Channel.SendMessageAsync(result.ErrorReason);
//}
} }
public async Task HandleMessageReceived(SocketMessage messsageParam) public async Task HandleMessageReceived(SocketMessage messsageParam)
@ -81,11 +92,11 @@ namespace Geekbot.net
if (message == null) return; if (message == null) return;
if (message.Author.Username.Contains("Geekbot")) return; if (message.Author.Username.Contains("Geekbot")) return;
var channel = (SocketGuildChannel) message.Channel; var channel = (SocketGuildChannel)message.Channel;
Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content); Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content);
var statsRecorder = new StatsRecorder(message); var statsRecorder = new StatsRecorder(message);
await statsRecorder.UpdateUserRecordAsync(); await statsRecorder.UpdateUserRecordAsync();
await statsRecorder.UpdateGuildRecordAsync(); await statsRecorder.UpdateGuildRecordAsync();
} }
@ -94,7 +105,7 @@ namespace Geekbot.net
{ {
if (!user.IsBot) if (!user.IsBot)
{ {
var message = redis.StringGet(user.Guild.Id + "-welcome-msg"); var message = redis.StringGet(user.Guild.Id + "-welcomeMsg");
if (!message.IsNullOrEmpty) if (!message.IsNullOrEmpty)
{ {
message = message.ToString().Replace("$user", user.Mention); message = message.ToString().Replace("$user", user.Mention);