Initial Commit
This commit is contained in:
commit
bb0db1701c
7 changed files with 187 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
Geekbot.net/bin
|
||||
Geekbot.net/obj
|
22
Geekbot.net.sln
Normal file
22
Geekbot.net.sln
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.0.0
|
||||
MinimumVisualStudioVersion = 10.0.0.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Geekbot.net", "Geekbot.net/Geekbot.net.csproj", "{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FDCB3D92-E7B5-47BB-A9B5-CFAEFA57CDB4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
23
Geekbot.net/Geekbot.net.csproj
Executable file
23
Geekbot.net/Geekbot.net.csproj
Executable file
|
@ -0,0 +1,23 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net">
|
||||
<Version>1.0.0-rc</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="RestSharp.NetCore">
|
||||
<Version>105.2.4-rc4-24214-01</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Net.Http">
|
||||
<Version>4.3.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.Serialization.Json">
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.Serialization.Primitives">
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
26
Geekbot.net/Modules/Cat.cs
Normal file
26
Geekbot.net/Modules/Cat.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using RestSharp;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Cat : ModuleBase
|
||||
{
|
||||
[Command("cat"), Summary("Return a random image of a cat.")]
|
||||
public async Task Say()
|
||||
{
|
||||
var client = new RestClient("http://random.cat");
|
||||
|
||||
var request = new RestRequest("meow.php", Method.GET);
|
||||
|
||||
var response = client.Execute<CatObject>(request);
|
||||
await ReplyAsync(response.Data.file);
|
||||
}
|
||||
}
|
||||
|
||||
public class CatObject
|
||||
{
|
||||
public string file {get;set;}
|
||||
}
|
||||
}
|
15
Geekbot.net/Modules/Ping.cs
Normal file
15
Geekbot.net/Modules/Ping.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Ping : ModuleBase
|
||||
{
|
||||
[Command("ping"), Summary("Pong.")]
|
||||
public async Task Say()
|
||||
{
|
||||
// ReplyAsync is a method on ModuleBase
|
||||
await ReplyAsync("Pong");
|
||||
}
|
||||
}
|
||||
}
|
23
Geekbot.net/Modules/UserInfo.cs
Normal file
23
Geekbot.net/Modules/UserInfo.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class UserInfo : ModuleBase
|
||||
{
|
||||
[Alias("stats", "whois")]
|
||||
[Command("user"), Summary("Get information about this user")]
|
||||
public async Task User([Summary("The (optional) user to get info for")] IUser user = null)
|
||||
{
|
||||
var userInfo = user ?? Context.Message.Author;
|
||||
|
||||
var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays);
|
||||
|
||||
await ReplyAsync($"{userInfo.Username}#{userInfo.Discriminator}\r\n" +
|
||||
$"Account created at {userInfo.CreatedAt.Day}.{userInfo.CreatedAt.Month}.{userInfo.CreatedAt.Year}, that is {age} days ago\r\n" +
|
||||
$"Currently {userInfo.Status}");
|
||||
}
|
||||
}
|
||||
}
|
76
Geekbot.net/Program.cs
Executable file
76
Geekbot.net/Program.cs
Executable file
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace Geekbot.net
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private CommandService commands;
|
||||
private DiscordSocketClient client;
|
||||
private DependencyMap map;
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Staring...");
|
||||
new Program().MainAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task MainAsync()
|
||||
{
|
||||
client = new DiscordSocketClient();
|
||||
commands = new CommandService();
|
||||
|
||||
string token = "MTgxMDkyOTgxMDUzNDU2Mzg0.C8_UTw.PvXLAVOTccbrWKLMeyvN9WqRPlU";
|
||||
|
||||
map = new DependencyMap();
|
||||
|
||||
await InstallCommands();
|
||||
|
||||
await client.LoginAsync(TokenType.Bot, token);
|
||||
await client.StartAsync();
|
||||
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
|
||||
public async Task InstallCommands()
|
||||
{
|
||||
// Hook the MessageReceived Event into our Command Handler
|
||||
client.MessageReceived += HandleCommand;
|
||||
client.MessageReceived += HandleMessageReceived;
|
||||
// Discover all of the commands in this assembly and load them.
|
||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||
}
|
||||
public async Task HandleCommand(SocketMessage messageParam)
|
||||
{
|
||||
// Don't process the command if it was a System Message
|
||||
var message = messageParam as SocketUserMessage;
|
||||
if (message == null) return;
|
||||
// Create a number to track where the prefix ends and the command begins
|
||||
int argPos = 0;
|
||||
// Determine if the message is a command, based on if it starts with '!' or a mention prefix
|
||||
if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return;
|
||||
// Create a Command Context
|
||||
var context = new CommandContext(client, message);
|
||||
// Execute the command. (result does not indicate a return value,
|
||||
// rather an object stating if the command executed succesfully)
|
||||
var result = await commands.ExecuteAsync(context, argPos, map);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
await context.Channel.SendMessageAsync(result.ErrorReason);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleMessageReceived(SocketMessage messsageParam)
|
||||
{
|
||||
var message = messsageParam;
|
||||
if (message == null) return;
|
||||
if (message.Author.Username.Contains("Geekbot")) return;
|
||||
|
||||
Console.WriteLine(message.Channel + " - " + message.Author + " - " + message.Content);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue