True Async and Ping Pong
This commit is contained in:
parent
341de410f1
commit
2af916e4d1
14 changed files with 87 additions and 46 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,4 +2,5 @@ Geekbot.net/bin
|
||||||
Geekbot.net/obj
|
Geekbot.net/obj
|
||||||
Backup/
|
Backup/
|
||||||
.vs/
|
.vs/
|
||||||
UpgradeLog.htm
|
UpgradeLog.htm
|
||||||
|
.idea
|
|
@ -14,7 +14,7 @@ namespace Geekbot.net.Modules
|
||||||
}
|
}
|
||||||
|
|
||||||
[RequireUserPermission(Discord.GuildPermission.Administrator)]
|
[RequireUserPermission(Discord.GuildPermission.Administrator)]
|
||||||
[Command("welcome"), Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
|
[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)
|
public async Task SetWelcomeMessage([Remainder, Summary("The message")] string welcomeMessage)
|
||||||
{
|
{
|
||||||
var key = Context.Guild.Id + "-welcomeMsg";
|
var key = Context.Guild.Id + "-welcomeMsg";
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Geekbot.net.Modules
|
||||||
this.catClient = catClient;
|
this.catClient = catClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("cat"), 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()
|
public async Task Say()
|
||||||
{
|
{
|
||||||
var request = new RestRequest("meow.php", Method.GET);
|
var request = new RestRequest("meow.php", Method.GET);
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Geekbot.net.Modules
|
||||||
redis = redisClient;
|
redis = redisClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("good"), Summary("Increase Someones Karma")]
|
[Command("good", RunMode = RunMode.Async), Summary("Increase Someones Karma")]
|
||||||
public async Task Good([Summary("The someone")] IUser user)
|
public async Task Good([Summary("The someone")] IUser user)
|
||||||
{
|
{
|
||||||
var lastKarma = GetLastKarma();
|
var lastKarma = GetLastKarma();
|
||||||
|
@ -37,7 +37,7 @@ namespace Geekbot.net.Modules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("bad"), Summary("Decrease Someones Karma")]
|
[Command("bad", RunMode = RunMode.Async), Summary("Decrease Someones Karma")]
|
||||||
public async Task Bad([Summary("The someone")] IUser user)
|
public async Task Bad([Summary("The someone")] IUser user)
|
||||||
{
|
{
|
||||||
var lastKarma = GetLastKarma();
|
var lastKarma = GetLastKarma();
|
||||||
|
|
|
@ -13,8 +13,7 @@ namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
rnd = randomClient;
|
rnd = randomClient;
|
||||||
}
|
}
|
||||||
|
[Command("8ball", RunMode = RunMode.Async), Summary("Ask 8Ball a Question.")]
|
||||||
[Command("8ball"), Summary("Ask 8Ball a Question.")]
|
|
||||||
public async Task Ball([Remainder, Summary("The Question")] string echo)
|
public async Task Ball([Remainder, Summary("The Question")] string echo)
|
||||||
{
|
{
|
||||||
var replies = new List<string> {
|
var replies = new List<string> {
|
||||||
|
|
47
Geekbot.net/Modules/GuildInfo.cs
Normal file
47
Geekbot.net/Modules/GuildInfo.cs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Discord;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Modules
|
||||||
|
{
|
||||||
|
public class GuildInfo : ModuleBase
|
||||||
|
{
|
||||||
|
private readonly IRedisClient redis;
|
||||||
|
public GuildInfo(IRedisClient redisClient)
|
||||||
|
{
|
||||||
|
redis = redisClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("serverstats", RunMode = RunMode.Async), Summary("Show some info about the bot.")]
|
||||||
|
public async Task getInfo()
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder();
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
public class Help : ModuleBase
|
public class Help : ModuleBase
|
||||||
{
|
{
|
||||||
[Command("help"), Summary("List all Commands")]
|
[Command("help", RunMode = RunMode.Async), Summary("List all Commands")]
|
||||||
public async Task GetHelp()
|
public async Task GetHelp()
|
||||||
{
|
{
|
||||||
var commands = new CommandService();
|
var commands = new CommandService();
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Discord.Commands;
|
|
||||||
using Discord;
|
|
||||||
using Geekbot.net.Lib;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
|
|
||||||
namespace Geekbot.net.Modules
|
namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
|
@ -16,33 +16,22 @@ namespace Geekbot.net.Modules
|
||||||
redis = redisClient;
|
redis = redisClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("serverstats"), Summary("Show some info about the bot.")]
|
[Command("info", RunMode = RunMode.Async), Summary("Get Information about the bot")]
|
||||||
public async Task getInfo()
|
public async Task BotInfo()
|
||||||
{
|
{
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder();
|
||||||
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");
|
eb.WithTitle("Geekbot V3");
|
||||||
var level = LevelCalc.GetLevelAtExperience((int)messages);
|
|
||||||
|
|
||||||
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.Client.StringGet("botOwner"))).Result;
|
||||||
eb.AddInlineField("Level", level)
|
|
||||||
.AddInlineField("Messages", messages);
|
eb.AddInlineField("Status", Context.Client.ConnectionState.ToString())
|
||||||
|
.AddInlineField("Bot Name", Context.Client.CurrentUser.Username)
|
||||||
|
.AddInlineField("Bot Owner", $"{botOwner.Username}#{botOwner.Discriminator}");
|
||||||
|
|
||||||
|
eb.AddInlineField("Servers", Context.Client.GetGuildsAsync().Result.Count);
|
||||||
|
|
||||||
await ReplyAsync("", false, eb.Build());
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
public class Ping : ModuleBase
|
public class Ping : ModuleBase
|
||||||
{
|
{
|
||||||
[Command("👀"), Summary("Look at the bot.")]
|
[Command("👀", RunMode = RunMode.Async), Summary("Look at the bot.")]
|
||||||
public async Task Eyes()
|
public async Task Eyes()
|
||||||
{
|
{
|
||||||
await ReplyAsync("S... Stop looking at me... baka!");
|
await ReplyAsync("S... Stop looking at me... baka!");
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Geekbot.net.Modules
|
||||||
rnd = randomClient;
|
rnd = randomClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("roll"), Summary("Roll a number between 1 and 100.")]
|
[Command("roll", RunMode = RunMode.Async), Summary("Roll a number between 1 and 100.")]
|
||||||
public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing")
|
public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing")
|
||||||
{
|
{
|
||||||
var number = rnd.Client.Next(1, 100);
|
var number = rnd.Client.Next(1, 100);
|
||||||
|
@ -38,7 +38,7 @@ namespace Geekbot.net.Modules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("dice"), Summary("Roll a dice")]
|
[Command("dice", RunMode = RunMode.Async), 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)
|
||||||
{
|
{
|
||||||
var number = rnd.Client.Next(1, max);
|
var number = rnd.Client.Next(1, max);
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace Geekbot.net.Modules
|
||||||
public class Say : ModuleBase
|
public class Say : ModuleBase
|
||||||
{
|
{
|
||||||
[RequireUserPermission(Discord.GuildPermission.Administrator)]
|
[RequireUserPermission(Discord.GuildPermission.Administrator)]
|
||||||
[Command("say"), Summary("Say Something.")]
|
[Command("say", RunMode = RunMode.Async), Summary("Say Something.")]
|
||||||
public async Task Echo([Remainder, Summary("What?")] string echo)
|
public async Task Echo([Remainder, Summary("What?")] string echo)
|
||||||
{
|
{
|
||||||
await Context.Message.DeleteAsync();
|
await Context.Message.DeleteAsync();
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Geekbot.net.Modules
|
||||||
}
|
}
|
||||||
|
|
||||||
[Alias("stats")]
|
[Alias("stats")]
|
||||||
[Command("user"), Summary("Get information about this user")]
|
[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)
|
public async Task User([Summary("The (optional) user to get info for")] IUser user = null)
|
||||||
{
|
{
|
||||||
var userInfo = user ?? Context.Message.Author;
|
var userInfo = user ?? Context.Message.Author;
|
||||||
|
@ -30,6 +30,7 @@ namespace Geekbot.net.Modules
|
||||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||||
.WithIconUrl(userInfo.GetAvatarUrl())
|
.WithIconUrl(userInfo.GetAvatarUrl())
|
||||||
.WithName(userInfo.Username));
|
.WithName(userInfo.Username));
|
||||||
|
|
||||||
eb.WithColor(new Color(221, 255, 119));
|
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)");
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
public class Youtube : ModuleBase
|
public class Youtube : ModuleBase
|
||||||
{
|
{
|
||||||
[Command("yt"), Summary("Search for something on youtube.")]
|
[Command("yt", RunMode = RunMode.Async), Summary("Search for something on youtube.")]
|
||||||
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
||||||
{
|
{
|
||||||
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||||
|
|
|
@ -54,32 +54,37 @@ namespace Geekbot.net
|
||||||
map.Add(redis);
|
map.Add(redis);
|
||||||
map.Add<IRandomClient>(new RandomClient());
|
map.Add<IRandomClient>(new RandomClient());
|
||||||
|
|
||||||
await InstallCommands();
|
|
||||||
Console.WriteLine("Connecting to Discord...");
|
Console.WriteLine("Connecting to Discord...");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await client.LoginAsync(TokenType.Bot, token);
|
await client.LoginAsync(TokenType.Bot, token);
|
||||||
await client.StartAsync();
|
await client.StartAsync();
|
||||||
|
client.Connected += FinishStartup;
|
||||||
}
|
}
|
||||||
catch (AggregateException)
|
catch (AggregateException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Could not connect to discord...");
|
Console.WriteLine("Could not connect to discord...");
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
Console.WriteLine("Done and ready for use...\n");
|
|
||||||
|
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task InstallCommands()
|
public async Task FinishStartup()
|
||||||
{
|
{
|
||||||
|
await client.SetGameAsync("Ping Pong");
|
||||||
|
Console.WriteLine($"Now Connected to {client.Guilds.Count} Servers");
|
||||||
|
|
||||||
|
Console.WriteLine("Registering Stuff");
|
||||||
|
|
||||||
client.MessageReceived += HandleCommand;
|
client.MessageReceived += HandleCommand;
|
||||||
client.MessageReceived += HandleMessageReceived;
|
client.MessageReceived += HandleMessageReceived;
|
||||||
|
|
||||||
client.UserJoined += HandleUserJoined;
|
client.UserJoined += HandleUserJoined;
|
||||||
|
|
||||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||||
|
|
||||||
|
Console.WriteLine("Done and ready for use...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleCommand(SocketMessage messageParam)
|
public async Task HandleCommand(SocketMessage messageParam)
|
||||||
{
|
{
|
||||||
var message = messageParam as SocketUserMessage;
|
var message = messageParam as SocketUserMessage;
|
||||||
|
@ -110,7 +115,6 @@ namespace Geekbot.net
|
||||||
{
|
{
|
||||||
var message = messsageParam;
|
var message = messsageParam;
|
||||||
if (message == null) return;
|
if (message == null) return;
|
||||||
// if (message.Author.Username.Equals(client.CurrentUser.Username)) return;
|
|
||||||
|
|
||||||
var channel = (SocketGuildChannel)message.Channel;
|
var channel = (SocketGuildChannel)message.Channel;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue