public static async Task ClearReactionsOnMessage(DiscordChannelMessage dMessage) { if (Program.DiscordClient.ConnectionState != ConnectionState.Connected) { return; } IMessage message = await(Program.DiscordClient.GetChannel(dMessage.ChannelID) as ISocketMessageChannel).GetMessageAsync(dMessage.MessageID); await message.RemoveAllReactionsAsync(); }
private async Task MarkMessage(BotChannel bChan, RolesSettings settings, DiscordChannelMessage dMessage, string topicToAdd) { await MisfitBot_MKII.DiscordWrap.DiscordClient.ClearReactionsOnMessage(dMessage); TopicDefinition topic = settings.Topics.Find(p => p.TopicName == topicToAdd); foreach (string role in topic.Roles) { if (settings.RoleTable.ContainsKey(role)) { await MisfitBot_MKII.DiscordWrap.DiscordClient.ReactionAdd(dMessage, settings.RoleTable[role]); } } //bool isSurrogate = Char.IsSurrogate(arg3.Emote.Name[0]); }
public static async Task ReactionAdd(DiscordChannelMessage dMessage, string emoteName) { if (Program.DiscordClient.ConnectionState != ConnectionState.Connected) { return; } IMessage message = await(Program.DiscordClient.GetChannel(dMessage.ChannelID) as ISocketMessageChannel).GetMessageAsync(dMessage.MessageID); GuildEmote emote; // Check if emote is unicode if (Char.IsSurrogate(emoteName, 0)) { // Resolve Unicode to emote object Emoji heartEmoji = new Emoji(emoteName); await message.AddReactionAsync(heartEmoji); } else { // resolve custom emote string[] parts = emoteName.Split(':'); emote = (message.Channel as SocketGuildChannel).Guild.Emotes.FirstOrDefault(x => x.Name == parts[1]); await message.AddReactionAsync(emote); } }
private async void OnCommandReceived(BotWideCommandArguments args) { if (args.source != MESSAGESOURCE.DISCORD) { return; } if (!args.canManageMessages) { return; } BotChannel bChan = await GetBotChannel(args); RolesSettings settings = await Settings <RolesSettings>(bChan, PLUGINNAME); BotWideResponseArguments response = new BotWideResponseArguments(args); if (args.command.ToLower() != "roles") { return; } // Helptext if (args.arguments.Count < 1) { InfoDump(bChan, settings, args); return; } // break down the command switch (args.arguments[0].ToLower()) { case "on": settings._active = true; SaveBaseSettings(bChan, PLUGINNAME, settings); response.message = $"Roles is active."; Respond(bChan, response); break; case "off": settings._active = false; SaveBaseSettings(bChan, PLUGINNAME, settings); response.message = $"Roles is inactive."; Respond(bChan, response); break; case "mark": if (!settings._active) { return; } if (args.arguments.Count < 3) { response.message = $"Not enough arguments. Use \"{CMC}roles mark <DiscordMessageID> <topic>\" as syntax. Get The ID by rightclicking the message when your Discordclient has developer mode turned on in advanced settings."; Respond(bChan, response); return; } if (!settings.Topics.Exists(p => p.TopicName == args.arguments[2])) { response.message = $"Can't find that topic. Doublecheck that it exist and you spelled it right."; Respond(bChan, response); } ulong msgID = Core.StringToUlong(args.arguments[1]); if (settings.MarkedMessages.Exists(p => p.MessageID == msgID)) { response.message = $"That message has already been marked with a topic. To replace it you have to unmark it first."; Respond(bChan, response); return; } DiscordChannelMessage dMessage = await MisfitBot_MKII.DiscordWrap.DiscordClient.DiscordGetMessage(response.discordChannel, msgID); if (dMessage == null) { response.message = $"Can't find that message. Make sure I got access to channel and rights to manage messages in it."; Respond(bChan, response); return; } response.message = $"Marking that message with the topic \"{args.arguments[2]}\"."; settings.MarkedMessages.Add(new MarkedMessage() { MessageID = msgID, Topic = args.arguments[2], TimeStamp = Core.CurrentTime }); await MarkMessage(bChan, settings, dMessage, args.arguments[2]); SaveBaseSettings(bChan, PLUGINNAME, settings); Respond(bChan, response); break; case "unmark": if (!settings._active) { return; } if (args.arguments.Count < 2) { response.message = $"Not enough arguments. Use \"{CMC}roles unmark <DiscordMessageID>\" as syntax. Get The ID by rightclicking the message when your Discordclient has developer mode turned on in advanced settings."; Respond(bChan, response); return; } ulong msgID2 = Core.StringToUlong(args.arguments[1]); if (!settings.MarkedMessages.Exists(p => p.MessageID == msgID2)) { response.message = $"That message isn't listed as marked."; Respond(bChan, response); return; } int removedNB = settings.MarkedMessages.RemoveAll(p => p.MessageID == msgID2); if (!settings.MarkedMessages.Exists(p => p.MessageID == msgID2)) { response.message = $"{removedNB} message has been unmarked."; SaveBaseSettings(bChan, PLUGINNAME, settings); Respond(bChan, response); return; } else { response.message = $"Something went wrong and message couldn't be unmarked. Try again and if it doesn't work complain to your mum."; Respond(bChan, response); return; } case "topic": if (!settings._active) { return; } if (args.arguments.Count < 2) { response.message = $"Topic is used to manage the topics. add/remove to create or delete topics. To add/remove roles to a topic use addrole/removerole."; Respond(bChan, response); return; } if (args.arguments[1].ToLower() == "add") { if (args.arguments.Count < 3) { response.message = $"Not enough arguments. Use \"{CMC}roles topic add <TheTopicNameYouWant>\" as syntax"; Respond(bChan, response); return; } if (TopicAdd(bChan, settings, args.arguments[2])) { response.message = $"Topic was added."; Respond(bChan, response); } else { response.message = $"Topic could not be added. Make sure it doens't already exist."; Respond(bChan, response); } } if (args.arguments[1].ToLower() == "remove") { if (args.arguments.Count < 3) { response.message = $"Not enough arguments. Use \"{CMC}roles topic remove <NameofTopic>\" as syntax"; Respond(bChan, response); return; } if (TopicRemove(bChan, settings, args.arguments[2])) { response.message = $"Topic was removed."; Respond(bChan, response); } else { response.message = $"Could not match topic."; Respond(bChan, response); } } if (args.arguments[1].ToLower() == "addrole") { if (args.arguments.Count < 4) { response.message = $"Not enough arguments. Use \"{CMC}roles topic addrole <Topic> <RoleYouWantAdded>\" as syntax"; Respond(bChan, response); return; } if (!MisfitBot_MKII.DiscordWrap.DiscordClient.DiscordRoleExist(bChan, args.arguments[3])) { response.message = $"That role does not exist on this Discord. This matching is case sensitive."; Respond(bChan, response); return; } if (!settings.RoleTable.ContainsKey(args.arguments[3])) { response.message = $"That role exists on the Discord but needs to be registered with an emote for this plugin. See the \"{CMC}roles role\" command."; Respond(bChan, response); return; } if (TopicAddRole(bChan, settings, args.arguments[2], args.arguments[3])) { response.message = $"Role({args.arguments[3]}) was added to topic({args.arguments[2]})."; Respond(bChan, response); } else { response.message = $"Role({args.arguments[3]}) could not be added to Topic({args.arguments[2]}). Make sure you type it right."; Respond(bChan, response); } } if (args.arguments[1].ToLower() == "removerole") { if (args.arguments.Count < 4) { response.message = $"Not enough arguments. Use \"{CMC}roles topic removerole <Topic> <RoleYouWantRemoved>\" as syntax"; Respond(bChan, response); return; } if (!settings.RoleTable.ContainsKey(args.arguments[3])) { response.message = $"That role cant be matched with the known roles for this plugin. See the \"{CMC}roles role\" command."; Respond(bChan, response); return; } if (TopicRemoveRole(bChan, settings, args.arguments[2], args.arguments[3])) { response.message = $"Role({args.arguments[3]}) was removed from topic({args.arguments[2]})."; Respond(bChan, response); } else { response.message = $"Role({args.arguments[3]}) could not be removed Topic({args.arguments[2]}). Make sure you type it right."; Respond(bChan, response); } } break; case "role": if (!settings._active) { return; } if (args.arguments.Count == 1) { response.message = $"This manages the roles. Make sure they exist on the Discord side of things. Use add/remove like \"{CMC}roles role <add/remove>\""; Respond(bChan, response); return; } if (args.arguments[1].ToLower() == "add") { if (args.arguments.Count < 4) { response.message = $"Not enough arguments. Use \"{CMC}roles role add <NameofDiscordrole> <NameofEmote>\" as syntax."; Respond(bChan, response); return; } if (!MisfitBot_MKII.DiscordWrap.DiscordClient.DiscordRoleExist(bChan, args.arguments[2])) { response.message = $"That role({args.arguments[2]}) does not exist on this Discord. This matching is case sensitive."; Respond(bChan, response); return; } if (!Char.IsSurrogate(args.arguments[3], 0)) { // Verify existence of custom emote if (!MisfitBot_MKII.DiscordWrap.DiscordClient.DiscordEmoteExist(bChan, args.arguments[3])) { response.message = $"That emote does not exist. This matching is case sensitive."; Respond(bChan, response); return; } } if (RoleAdd(bChan, settings, args.arguments[2], args.arguments[3])) { response.message = $"Role was added."; Respond(bChan, response); } else { response.message = $"Could not add role. Make sure role and emote isn't already used."; Respond(bChan, response); } } if (args.arguments[1].ToLower() == "remove") { // TODO also remove from topics if (args.arguments.Count < 3) { response.message = $"Not enough arguments. Use \"{CMC}roles role remove <NameofDiscordrole>\" as syntax."; Respond(bChan, response); return; } if (RoleRemove(bChan, settings, args.arguments[2])) { response.message = $"Role was removed."; Respond(bChan, response); } else { response.message = $"Could not match role."; Respond(bChan, response); } } if (args.arguments[1].ToLower() == "editemote") { if (args.arguments.Count < 4) { response.message = $"Not enough arguments. Use \"{CMC}roles role editemote <RoleToEdit> <NewEmote>\" as syntax"; Respond(bChan, response); return; } if (!settings.RoleTable.ContainsKey(args.arguments[2])) { response.message = $"Can't find that role. Make sure you enter it correctly and remember it is case sensitive."; Respond(bChan, response); return; } if (settings.RoleTable[args.arguments[2]] == args.arguments[3]) { response.message = $"That is the already stored emote for that role. Baka!"; Respond(bChan, response); } if (RoleEdit(bChan, settings, args.arguments[2], args.arguments[3])) { response.message = $"The role {args.arguments[2]}'s emote was updated to {args.arguments[3]}."; Respond(bChan, response); } else { response.message = $"Failed to change the emote."; Respond(bChan, response); } } break; } }// EOF OnCommandReceived