using EmbedIO; using EmbedIO.Routing; using EmbedIO.WebApi; using OpenMetaverse; using SecondBotEvents.Services; using System; using System.Collections.Generic; namespace SecondBotEvents.Commands { public class DiscordCommands : CommandsAPI { public DiscordCommands(EventsSecondBot setmaster) : base(setmaster) { } [About("Adds a discord server role to the selected member")] [ReturnHintsFailure("Discord client not ready")] [ReturnHints("true|false")] [ArgHints("serverid","URLARG","the server id to apply this action to")] [ArgHints("roleid", "URLARG", "the role id we are giving")] [ArgHints("memberid", "URLARG", "who we are giving it to")] [Route(HttpVerbs.Get, "/Discord_AddRole/{serverid}/{roleid}/{memberid}/{token}")] public object Discord_AddRole(string serverid,string roleid,string memberid,string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } return BasicReply(master.DiscordService.addRoleToMember(serverid, roleid, memberid).Result.ToString(), "Discord_AddRole", new [] { serverid, roleid, memberid }); } [About("Adds the selected user to the ban list - Disallows rejoining untill they are removed from the list")] [ReturnHintsFailure("Discord client not ready")] [ReturnHintsFailure("Why empty")] [ReturnHints("true|false")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("memberid", "URLARG", "who we are giving it to")] [ArgHints("why", "string", "why they are being banned")] [Route(HttpVerbs.Post, "/Discord_BanMember/{serverid}/{memberid}/{token}")] public object Discord_BanMember(string serverid, string memberid, [FormField] string why, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } if (SecondbotHelpers.notempty(why) == false) { return Failure("Why empty", "Discord_BanMember", new [] { serverid, memberid, why }); } return BasicReply(master.DiscordService.BanMember(serverid, memberid, why).Result.ToString(), "Discord_BanMember", new [] { serverid, memberid, why }); } [About("Clears messages on the server sent by the member in the last 13 days, 22hours 59mins")] [ReturnHintsFailure("Discord client not ready")] [ReturnHints("true|false")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("memberid", "URLARG", "who we are giving it to")] [Route(HttpVerbs.Get, "/Discord_BulkClear_Messages/{serverid}/{memberid}/{token}")] public object Discord_BulkClear_Messages(string serverid, string memberid, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } SuccessNoReturn("Discord_BulkClear_Messages", new [] { serverid, memberid }); return master.DiscordService.ClearMessages(serverid, memberid).Result; } [About("Sends a message directly to the user [They must be in the server]\n This command requires the SERVER MEMBERS INTENT found in discord app dev")] [ReturnHintsFailure("Discord client not ready")] [ReturnHints("true|false")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("memberid", "URLARG", "who we are giving it to")] [ArgHints("message", "Text", "what we are sending")] [Route(HttpVerbs.Post, "/Discord_Dm_Member/{serverid}/{memberid}/{token}")] public object Discord_Dm_Member(string serverid, string memberid, [FormField] string message, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } return BasicReply(master.DiscordService.MessageMember(serverid, memberid, message).Result.ToString(), "Discord_Dm_Member", new [] { serverid, memberid, message }); } [About("Returns a list of members in a server \n collection is userid: username \n if the user has set a nickname: userid: nickname|username \n" + " This command requires Discord full client mode enabled and connected\n !!!! This command also requires: Privileged Gateway Intents / " + "SERVER MEMBERS INTENT set to true on the discord bot api area !!!")] [ReturnHintsFailure("Discord client not ready")] [ReturnHints("mixed array of userid: nickname|username or userid:username")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [Route(HttpVerbs.Get, "/Discord_MembersList/{serverid}/{token}")] public object Discord_MembersList(string serverid, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } SuccessNoReturn("Discord_MembersList", new [] { serverid }); return master.DiscordService.ListMembers(serverid).Result; } [About("Sends a message to the selected channel - Optional TTS usage")] [ReturnHintsFailure("Discord client not ready")] [ReturnHintsFailure("message empty")] [ReturnHints("true|false")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("channelid", "URLARG", "the channel id to apply this action to")] [ArgHints("tts", "URLARG", "shoud tts be enabled true or false")] [ArgHints("message", "Text", "what we are sending")] [Route(HttpVerbs.Post, "/Discord_MembersList/{serverid}/{tts}/{token}")] public object Discord_MessageChannel(string serverid, string channelid, string tts, [FormField] string message, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } if (SecondbotHelpers.notempty(message) == false) { return Failure("message empty", "Discord_MessageChannel", new [] { serverid, channelid, tts, message }); } return BasicReply(master.DiscordService.MessageChannel(serverid, channelid, message, tts).Result.ToString(), "Discord_MessageChannel", new [] { serverid, channelid, tts, message }); } [About("Sends a message to the selected channel - Optional TTS usage")] [ReturnHints("mixed array of userid: nickname|username or userid:username")] [ReturnHintsFailure("Discord client not ready")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("memberid", "URLARG", "who we are giving it to")] [ArgHints("mode", "URLARG", "should we mute them \"true\" or unmute \"false\"")] [Route(HttpVerbs.Get, "/Discord_MuteMember/{serverid}/{memberid}/{mode}/{token}")] public object Discord_MuteMember(string serverid, string memberid, string mode, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } return BasicReply(master.DiscordService.MuteMember(serverid, memberid, mode).Result.ToString(), "Discord_MuteMember", new [] { serverid, memberid, mode }); } [About("returns a collection of settings for the given role \n This command requires Discord full client mode enabled and connected")] [ReturnHints("KeyPair of status: KeyPair[] item = value")] [ReturnHintsFailure("Discord client not ready")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("memberid", "URLARG", "who we are giving it to")] [ArgHints("mode", "URLARG", "should we mute them \"true\" or unmute \"false\"")] [Route(HttpVerbs.Get, "/Discord_Role_GetSettings/{serverid}/{roleid}/{token}")] public object Discord_Role_GetSettings(string serverid, string roleid, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } SuccessNoReturn("Discord_Role_GetSettings", new [] { serverid, roleid }); return master.DiscordService.RoleSettings(serverid,roleid); } [About("Updates perm flags for the selected role \n example CSV format: Speak=True,SendMessages=False \n for a full list of perms see output of Discord_Role_GetSettings \n" + " This command requires Discord full client mode enabled and connected")] [ReturnHints("true|false")] [ReturnHintsFailure("Discord client not ready")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("roleid", "URLARG", "who we are giving it to")] [ArgHints("flagscsv", "Text", "what we are setting")] [Route(HttpVerbs.Post, "/Discord_Role_UpdatePerms/{serverid}/{roleid}/{token}")] public object Discord_Role_UpdatePerms(string serverid, string roleid, [FormField] string flagscsv, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } return BasicReply(master.DiscordService.UpdateRolePerms(serverid, roleid, flagscsv).Result.ToString(), "Discord_Role_UpdatePerms", new [] { serverid, roleid, flagscsv }); } [About("Updates perm flags for the selected role \n example CSV format: Speak=True,SendMessages=False \n for a full list of perms see output of Discord_Role_GetSettings \n" + " This command requires Discord full client mode enabled and connected")] [ReturnHints("KeyPair of statusmessage=roleid or 0")] [ReturnHintsFailure("Discord client not ready")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("role", "URLARG", "the name of the role we are creating")] [Route(HttpVerbs.Get, "/Discord_RoleCreate/{serverid}/{role}/{token}")] public object Discord_RoleCreate(string serverid, string role, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } SuccessNoReturn("Discord_RoleCreate", new [] { serverid, role }); return master.DiscordService.CreateRole(serverid,role).Result; } [About("Returns a list of roles and their ids in collection \n This command requires Discord full client mode enabled and connected")] [ReturnHints("KeyPair of status: KeyPair of roleid: rolename")] [ReturnHintsFailure("Discord client not ready")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [Route(HttpVerbs.Get, "/Discord_RoleList/{serverid}/{token}")] public object Discord_RoleList(string serverid, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } return BasicReply(master.DiscordService.ListRoles(serverid).ToString(), "Discord_RoleList", new [] { serverid }); } [About("Remove a role from a server \n This command requires Discord full client mode enabled and connected")] [ReturnHints("true|false")] [ReturnHintsFailure("Discord client not ready")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [Route(HttpVerbs.Get, "/Discord_RoleRemove/{serverid}/{roleid}/{token}")] public object Discord_RoleRemove(string serverid, string roleid, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } return BasicReply(master.DiscordService.RemoveRole(serverid, roleid).Result.ToString(), "Discord_RoleRemove", new [] { serverid, roleid }); } [About("Returns a list of text channels in a server")] [ReturnHints("array of channelid: name")] [ReturnHintsFailure("Discord client not ready")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [Route(HttpVerbs.Get, "/Discord_TextChannels_List/{serverid}/{roleid}/{token}")] public object Discord_TextChannels_List(string serverid, string token) { if (AllowToken(token) == false) { return Failure("Token not accepted"); } if (master.DiscordService.DiscordReady() == false) { return Failure("Discord client not ready"); } return master.DiscordService.ListTextChannels(serverid); } } }