Skip to content

Commit

Permalink
Moved some stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
AridTag committed Apr 7, 2018
1 parent edd1506 commit d912195
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,26 @@ private async Task DiscordClientMessageReceived(SocketMessage arg)
{
return;
}

// TODO: I'm not sure when this would ever NOT be a SocketGuildUser...direct message maybe?
// should we handle direct messages?
var user = arg.Author as SocketGuildUser;
if (user == null)
{
return;
}


int commandStartIndex = 0;
if(message.HasCharPrefix(_settings.CommandPrefix, ref commandStartIndex))
if (message.HasCharPrefix(_settings.CommandPrefix, ref commandStartIndex))
{
var commandInfo = CommandParser.Parse(message.Content, commandStartIndex);

if (!string.IsNullOrWhiteSpace(commandInfo.commandWord))
if (arg.Author is SocketGuildUser guildUser)
{
RaiseOnCommandReceived(user, commandInfo.commandWord, commandInfo.arguments);
GuildMessageReceived(guildUser, commandStartIndex, arg.Content);
}

// TODO: arg.Author could be of type SocketGlobalUser (but the type is internal...) which means we got a direct message.
// I'm not sure how else I can detect the difference I'm not seeing anything obvious in the API
}
}

private void GuildMessageReceived(SocketGuildUser user, int commandStartIndex, string message)
{
var commandInfo = CommandParser.Parse(message, commandStartIndex);
if (!string.IsNullOrWhiteSpace(commandInfo.commandWord))
{
RaiseOnCommandReceived(user, commandInfo.commandWord, commandInfo.arguments);
}
}

Expand Down

0 comments on commit d912195

Please sign in to comment.