Skip to content

Commit d912195

Browse files
committed
Moved some stuff around
1 parent edd1506 commit d912195

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,26 @@ private async Task DiscordClientMessageReceived(SocketMessage arg)
5454
{
5555
return;
5656
}
57-
58-
// TODO: I'm not sure when this would ever NOT be a SocketGuildUser...direct message maybe?
59-
// should we handle direct messages?
60-
var user = arg.Author as SocketGuildUser;
61-
if (user == null)
62-
{
63-
return;
64-
}
65-
57+
6658
int commandStartIndex = 0;
67-
if(message.HasCharPrefix(_settings.CommandPrefix, ref commandStartIndex))
59+
if (message.HasCharPrefix(_settings.CommandPrefix, ref commandStartIndex))
6860
{
69-
var commandInfo = CommandParser.Parse(message.Content, commandStartIndex);
70-
71-
if (!string.IsNullOrWhiteSpace(commandInfo.commandWord))
61+
if (arg.Author is SocketGuildUser guildUser)
7262
{
73-
RaiseOnCommandReceived(user, commandInfo.commandWord, commandInfo.arguments);
63+
GuildMessageReceived(guildUser, commandStartIndex, arg.Content);
7464
}
65+
66+
// TODO: arg.Author could be of type SocketGlobalUser (but the type is internal...) which means we got a direct message.
67+
// I'm not sure how else I can detect the difference I'm not seeing anything obvious in the API
68+
}
69+
}
70+
71+
private void GuildMessageReceived(SocketGuildUser user, int commandStartIndex, string message)
72+
{
73+
var commandInfo = CommandParser.Parse(message, commandStartIndex);
74+
if (!string.IsNullOrWhiteSpace(commandInfo.commandWord))
75+
{
76+
RaiseOnCommandReceived(user, commandInfo.commandWord, commandInfo.arguments);
7577
}
7678
}
7779

0 commit comments

Comments
 (0)