Added Discord Bot
This commit is contained in:
parent
e7a0c9ae68
commit
e445b2a181
48 changed files with 1255 additions and 157 deletions
62
Lieb/Discord/CommandHandler.cs
Normal file
62
Lieb/Discord/CommandHandler.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Lieb.Discord
|
||||
{
|
||||
public class CommandHandler
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly CommandService _commands;
|
||||
|
||||
// Retrieve client and CommandService instance via ctor
|
||||
public CommandHandler(DiscordSocketClient client, CommandService commands)
|
||||
{
|
||||
_commands = commands;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task InstallCommandsAsync()
|
||||
{
|
||||
// Hook the MessageReceived event into our command handler
|
||||
_client.MessageReceived += HandleCommandAsync;
|
||||
|
||||
// Here we discover all of the command modules in the entry
|
||||
// assembly and load them. Starting from Discord.NET 2.0, a
|
||||
// service provider is required to be passed into the
|
||||
// module registration method to inject the
|
||||
// required dependencies.
|
||||
//
|
||||
// If you do not use Dependency Injection, pass null.
|
||||
// See Dependency Injection guide for more information.
|
||||
await _commands.AddModulesAsync(assembly: Assembly.GetEntryAssembly(),
|
||||
services: null);
|
||||
}
|
||||
|
||||
private async Task HandleCommandAsync(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 the prefix and make sure no bots trigger commands
|
||||
if (!(message.HasCharPrefix('!', ref argPos) ||
|
||||
message.HasMentionPrefix(_client.CurrentUser, ref argPos)) ||
|
||||
message.Author.IsBot)
|
||||
return;
|
||||
|
||||
// Create a WebSocket-based command context based on the message
|
||||
var context = new SocketCommandContext(_client, message);
|
||||
|
||||
// Execute the command with the command context we just
|
||||
// created, along with the service provider for precondition checks.
|
||||
await _commands.ExecuteAsync(
|
||||
context: context,
|
||||
argPos: argPos,
|
||||
services: null);
|
||||
}
|
||||
}
|
||||
}
|
25
Lieb/Discord/Messages/RaidMessage.cs
Normal file
25
Lieb/Discord/Messages/RaidMessage.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Lieb.Models.GuildWars2.Raid;
|
||||
|
||||
namespace Lieb.Discord.Messages
|
||||
{
|
||||
public class RaidMessage
|
||||
{
|
||||
private Raid _raid;
|
||||
|
||||
public RaidMessage(Raid raid)
|
||||
{
|
||||
_raid = raid;
|
||||
}
|
||||
|
||||
public void PostRaidMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void UpdateRaidMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue