RegexBot/Modules/ModCommands/Commands/Say.cs
Noi 1149f2800d Reorganized project
Moved modules into the assembly itself to simplify development of
further features and reduce complexity in building this project.

Additionally, many small adjustments were made, including:
- Add documentation to most public methods that had it missing
- Minor style updates
- Updated readme to reflect near-completion of this rewrite
- Remove any last remaining references to old project name Kerobot
- Update dependencies
2022-07-20 18:55:08 -07:00

34 lines
1.4 KiB
C#

using RegexBot.Common;
namespace RegexBot.Modules.ModCommands.Commands;
class Say : CommandConfig {
private readonly string _usage;
protected override string DefaultUsageMsg => _usage;
// No configuration at the moment.
// TODO: Whitelist/blacklist - to limit which channels it can "say" into
public Say(ModCommands module, JObject config) : base(module, config) {
_usage = $"{Command} `channel` `message`\n"
+ "Displays the given message exactly as specified to the given channel.";
}
public override async Task Invoke(SocketGuild g, SocketMessage msg) {
var line = msg.Content.Split(new char[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);
if (line.Length <= 1) {
await SendUsageMessageAsync(msg.Channel, ":x: You must specify a channel.");
return;
}
if (line.Length <= 2 || string.IsNullOrWhiteSpace(line[2])) {
await SendUsageMessageAsync(msg.Channel, ":x: You must specify a message.");
return;
}
var getCh = Utilities.ChannelMention.Match(line[1]);
if (!getCh.Success) {
await SendUsageMessageAsync(msg.Channel, ":x: Unable to find given channel.");
return;
}
var ch = g.GetTextChannel(ulong.Parse(getCh.Groups["snowflake"].Value));
await ch.SendMessageAsync(line[2]);
}
}