Testing the new discord API commands
This commit is contained in:
parent
0bfe466bbd
commit
e9c6f5b0cb
16 changed files with 881 additions and 4 deletions
|
|
@ -69,6 +69,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
protected override void login_bot(bool self_keep_alive)
|
protected override void login_bot(bool self_keep_alive)
|
||||||
{
|
{
|
||||||
controler = new CliExitOnLogout(myconfig, running_as_docker, self_keep_alive);
|
controler = new CliExitOnLogout(myconfig, running_as_docker, self_keep_alive);
|
||||||
|
controler.Bot.setDiscordClient(DiscordClient);
|
||||||
attach_events();
|
attach_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BSB.Commands.Avatars
|
namespace BSB.Commands.Avatars
|
||||||
{
|
{
|
||||||
class NearMe : CoreCommand_SmartReply_1arg
|
class RoleCreate : CoreCommand_SmartReply_1arg
|
||||||
{
|
{
|
||||||
public override string Helpfile { get { return "Gets a list of avatars near the bot"; } }
|
public override string Helpfile { get { return "Gets a list of avatars near the bot"; } }
|
||||||
public override bool CallFunction(string[] args)
|
public override bool CallFunction(string[] args)
|
||||||
|
|
|
||||||
53
Core/Commands/DiscordAPI/AddRole.cs
Normal file
53
Core/Commands/DiscordAPI/AddRole.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_AddRole : CoreCommand_4arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number", "Number" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Role id", "Member id" }; } }
|
||||||
|
public override string Helpfile { get { return "Adds the selected role to the member"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
bool reply = addRoleToMember(args).Result;
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<bool> addRoleToMember(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
if(ulong.TryParse(args[2], out ulong roleid) == true)
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(args[3], out ulong memberid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
SocketRole role = server.GetRole(roleid);
|
||||||
|
SocketGuildUser user = server.GetUser(memberid);
|
||||||
|
await user.AddRoleAsync(role); // ? Irole seems to accept SocketRole ?
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
54
Core/Commands/DiscordAPI/Ban_Member.cs
Normal file
54
Core/Commands/DiscordAPI/Ban_Member.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_BanMember : CoreCommand_3arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number","Text" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Member id","Optional why message" }; } }
|
||||||
|
public override string Helpfile { get { return "Adds the selected user to the ban list - Disallows rejoining untill they are removed from the list "; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
bool reply = BanMember(args).Result;
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<bool> BanMember(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(args[2], out ulong memberid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
SocketGuildUser user = server.GetUser(memberid);
|
||||||
|
string why = "Secondbot API ban - see your own logs";
|
||||||
|
if (args.Length == 4)
|
||||||
|
{
|
||||||
|
why = args[3];
|
||||||
|
}
|
||||||
|
await user.BanAsync(7, why);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
75
Core/Commands/DiscordAPI/BulkClear_Messages.cs
Normal file
75
Core/Commands/DiscordAPI/BulkClear_Messages.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_BulkClear_Messages : CoreCommand_3arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Member id" }; } }
|
||||||
|
public override string Helpfile { get { return "Clears messages on the server sent by the member in the last 13 days, 22hours 59mins"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
KeyValuePair<bool, int> reply = ClearMessages(args).Result;
|
||||||
|
Dictionary<string, string> collection = new Dictionary<string, string>();
|
||||||
|
collection.Add("Deleted", reply.Value.ToString());
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "See status for state, see collection for total deleted", CommandName, collection);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<KeyValuePair<bool,int>> ClearMessages(string[] args)
|
||||||
|
{
|
||||||
|
int messagesDeleted = 0;
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(args[2], out ulong memberid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
SocketGuildUser user = server.GetUser(memberid);
|
||||||
|
TimeSpan somedays = new TimeSpan(13, 22, 59, 59, 0);
|
||||||
|
DateTimeOffset justundertwosweeks = DateTimeOffset.Now;
|
||||||
|
justundertwosweeks = justundertwosweeks.Subtract(somedays);
|
||||||
|
long unixtimelimit = justundertwosweeks.ToUnixTimeSeconds();
|
||||||
|
foreach (SocketTextChannel channel in server.TextChannels)
|
||||||
|
{
|
||||||
|
List<IMessage> DeleteMessages = new List<IMessage>();
|
||||||
|
IEnumerable<IMessage> messages = await channel.GetMessagesAsync(100).FlattenAsync();
|
||||||
|
foreach (IMessage message in messages)
|
||||||
|
{
|
||||||
|
if (message.CreatedAt.ToUnixTimeSeconds() > unixtimelimit)
|
||||||
|
{
|
||||||
|
if (message.Author.Id == user.Id)
|
||||||
|
{
|
||||||
|
DeleteMessages.Add(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(DeleteMessages.Count() > 0)
|
||||||
|
{
|
||||||
|
messagesDeleted += DeleteMessages.Count();
|
||||||
|
await channel.DeleteMessagesAsync(DeleteMessages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, int>(true, messagesDeleted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, int>(false,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Core/Commands/DiscordAPI/Dm_Member.cs
Normal file
45
Core/Commands/DiscordAPI/Dm_Member.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_Dm_Member : CoreCommand_3arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Text" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Member id", "Message" }; } }
|
||||||
|
public override string Helpfile { get { return "Sends a message directly to the user \n This will fail if they are not friends or dont share a server!"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
bool reply = MessageMember(args).Result;
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<bool> MessageMember(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong memberid) == true)
|
||||||
|
{
|
||||||
|
SocketUser user = Discord.GetUser(memberid);
|
||||||
|
await user.SendMessageAsync(args[2]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
58
Core/Commands/DiscordAPI/MembersList.cs
Normal file
58
Core/Commands/DiscordAPI/MembersList.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_MembersList : CoreCommand_SmartReply_2arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id" }; } }
|
||||||
|
public override string Helpfile { get { return "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 !!!"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
KeyValuePair<bool, Dictionary<string, string>> reply = ListMembers(args).Result;
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "see status for state", CommandName, reply.Value);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<KeyValuePair<bool, Dictionary<string, string>>> ListMembers(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
IEnumerable<IGuildUser> users = await server.GetUsersAsync().FlattenAsync().ConfigureAwait(true);
|
||||||
|
Dictionary<string, string> membersList = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
foreach (IGuildUser user in users)
|
||||||
|
{
|
||||||
|
if (user.Nickname != null)
|
||||||
|
{
|
||||||
|
membersList.Add(user.Id.ToString(), user.Nickname+"|"+user.Username);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
membersList.Add(user.Id.ToString(), user.Username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, Dictionary<string, string>>(true, membersList);
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, Dictionary<string, string>>(false, new Dictionary<string, string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
Core/Commands/DiscordAPI/MessageChannel.cs
Normal file
65
Core/Commands/DiscordAPI/MessageChannel.cs
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_MessageChannel : CoreCommand_4arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number", "Message", "True|False" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "channel id", "Message to send", "Use TTS defaults to False" }; } }
|
||||||
|
public override string Helpfile { get { return "Sends a message to the selected channel - Optional TTS usage"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
bool reply = MessageChannel(args).Result;
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<bool> MessageChannel(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(args[2], out ulong channelid) == true)
|
||||||
|
{
|
||||||
|
bool useTTS = false;
|
||||||
|
if(args.Length == 5)
|
||||||
|
{
|
||||||
|
bool.TryParse(args[4], out useTTS);
|
||||||
|
}
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
SocketTextChannel Channel = null;
|
||||||
|
foreach (SocketTextChannel channel in server.TextChannels)
|
||||||
|
{
|
||||||
|
if(channel.Id == channelid)
|
||||||
|
{
|
||||||
|
Channel = channel;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Channel != null)
|
||||||
|
{
|
||||||
|
await Channel.SendMessageAsync(args[3], useTTS);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
Core/Commands/DiscordAPI/MuteMember.cs
Normal file
57
Core/Commands/DiscordAPI/MuteMember.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_MuteMember : CoreCommand_3arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number", "True|False" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Member id", "{Optional} Mute status (defaults to true) set this to False to unmute" }; } }
|
||||||
|
public override string Helpfile { get { return "Updates the Mute status of the member"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
bool reply = MuteMember(args).Result;
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<bool> MuteMember(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(args[2], out ulong memberid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
SocketGuildUser user = server.GetUser(memberid);
|
||||||
|
bool status = true;
|
||||||
|
if (args.Length == 4)
|
||||||
|
{
|
||||||
|
bool.TryParse(args[3], out status);
|
||||||
|
}
|
||||||
|
await user.ModifyAsync(pr =>
|
||||||
|
{
|
||||||
|
pr.Mute = status;
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
Core/Commands/DiscordAPI/RoleCreate.cs
Normal file
47
Core/Commands/DiscordAPI/RoleCreate.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_RoleCreate : CoreCommand_SmartReply_3arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart","Number","Text" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]","Discord server id","Role name" }; } }
|
||||||
|
public override string Helpfile { get { return "Creates a new role and returns its role ID via smart target\n This command requires Discord full client mode enabled and connected"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if(bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
KeyValuePair<string, ulong> reply = CreateRole(args).Result;
|
||||||
|
Dictionary<string, string> collection = new Dictionary<string, string>();
|
||||||
|
collection.Add("roleid", reply.Value.ToString());
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(true, args[0], "ok", CommandName, collection);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<KeyValuePair<string,ulong>> CreateRole(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
RestRole role = await server.CreateRoleAsync(args[2], new GuildPermissions(), Color.DarkRed, false, null).ConfigureAwait(true);
|
||||||
|
return new KeyValuePair<string, ulong>("ok", role.Id);
|
||||||
|
}
|
||||||
|
return new KeyValuePair<string, ulong>("Unable to process server id", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
Core/Commands/DiscordAPI/RoleList.cs
Normal file
49
Core/Commands/DiscordAPI/RoleList.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_RoleList: CoreCommand_SmartReply_2arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id" }; } }
|
||||||
|
public override string Helpfile { get { return "Returns a list of roles and their ids in collection \n This command requires Discord full client mode enabled and connected"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
KeyValuePair<bool, Dictionary<string, string>> reply = ListRoles(args);
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "see status for state", CommandName, reply.Value);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected KeyValuePair<bool,Dictionary<string,string>> ListRoles(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
Dictionary<string, string> rolesList = new Dictionary<string, string>();
|
||||||
|
foreach (SocketRole role in server.Roles)
|
||||||
|
{
|
||||||
|
rolesList.Add(role.Id.ToString(), role.Name);
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, Dictionary<string, string>>(true, rolesList);
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, Dictionary<string, string>>(false,new Dictionary<string, string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
Core/Commands/DiscordAPI/RoleRemove.cs
Normal file
49
Core/Commands/DiscordAPI/RoleRemove.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_RoleRemove: CoreCommand_SmartReply_3arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Role id" }; } }
|
||||||
|
public override string Helpfile { get { return "Remove a new role from a server \n This command requires Discord full client mode enabled and connected"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
bool status = RemoveRole(args).Result;
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(status, args[0], "see status for removal state", CommandName);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<bool> RemoveRole(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(args[2], out ulong roleid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
SocketRole role = server.GetRole(roleid);
|
||||||
|
await role.DeleteAsync().ConfigureAwait(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
84
Core/Commands/DiscordAPI/Role_GetSettings.cs
Normal file
84
Core/Commands/DiscordAPI/Role_GetSettings.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_Role_GetSettings : CoreCommand_SmartReply_3arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Role id" }; } }
|
||||||
|
public override string Helpfile { get { return "returns a collection of settings for the given role \n This command requires Discord full client mode enabled and connected"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
KeyValuePair<bool, Dictionary<string, string>> reply = RoleSettings(args);
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "see status for state", CommandName,reply.Value);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected KeyValuePair<bool, Dictionary<string, string>> RoleSettings(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(args[2], out ulong roleid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
SocketRole role = server.GetRole(roleid);
|
||||||
|
Dictionary<string, string> settings = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "Config|Color", String.Join(",", new byte[3] { role.Color.R, role.Color.G, role.Color.B }) },
|
||||||
|
{ "Config|Name", role.Name },
|
||||||
|
{ "Info|AssignedCount", role.Members.Count().ToString() },
|
||||||
|
{ "Perm|AttachFiles", role.Permissions.AttachFiles.ToString() },
|
||||||
|
{ "Perm|ReadMessageHistory", role.Permissions.ReadMessageHistory.ToString() },
|
||||||
|
{ "Perm|MentionEveryone", role.Permissions.MentionEveryone.ToString() },
|
||||||
|
{ "Perm|UseExternalEmojis", role.Permissions.UseExternalEmojis.ToString() },
|
||||||
|
{ "Perm|Connect", role.Permissions.Connect.ToString() },
|
||||||
|
{ "Perm|Speak", role.Permissions.Speak.ToString() },
|
||||||
|
{ "Perm|MuteMembers", role.Permissions.MuteMembers.ToString() },
|
||||||
|
{ "Perm|UseVAD", role.Permissions.UseVAD.ToString() },
|
||||||
|
{ "Perm|MoveMembers", role.Permissions.MoveMembers.ToString() },
|
||||||
|
{ "Perm|EmbedLinks", role.Permissions.EmbedLinks.ToString() },
|
||||||
|
{ "Perm|PrioritySpeaker", role.Permissions.PrioritySpeaker.ToString() },
|
||||||
|
{ "Perm|Stream", role.Permissions.Stream.ToString() },
|
||||||
|
{ "Perm|ChangeNickname", role.Permissions.ChangeNickname.ToString() },
|
||||||
|
{ "Perm|ManageNicknames", role.Permissions.ManageNicknames.ToString() },
|
||||||
|
{ "Perm|ManageRoles", role.Permissions.ManageRoles.ToString() },
|
||||||
|
{ "Perm|DeafenMembers", role.Permissions.DeafenMembers.ToString() },
|
||||||
|
{ "Perm|ManageMessages", role.Permissions.ManageMessages.ToString() },
|
||||||
|
{ "Perm|ViewChannel", role.Permissions.ViewChannel.ToString() },
|
||||||
|
{ "Perm|SendMessages", role.Permissions.SendMessages.ToString() },
|
||||||
|
{ "Perm|CreateInstantInvite", role.Permissions.CreateInstantInvite.ToString() },
|
||||||
|
{ "Perm|BanMembers", role.Permissions.BanMembers.ToString() },
|
||||||
|
{ "Perm|SendTTSMessages", role.Permissions.SendTTSMessages.ToString() },
|
||||||
|
{ "Perm|Administrator", role.Permissions.Administrator.ToString() },
|
||||||
|
{ "Perm|ManageChannels", role.Permissions.ManageChannels.ToString() },
|
||||||
|
{ "Perm|KickMembers", role.Permissions.KickMembers.ToString() },
|
||||||
|
{ "Perm|AddReactions", role.Permissions.AddReactions.ToString() },
|
||||||
|
{ "Perm|ViewAuditLog", role.Permissions.ViewAuditLog.ToString() },
|
||||||
|
{ "Perm|ManageWebhooks", role.Permissions.ManageWebhooks.ToString() },
|
||||||
|
{ "Perm|ManageGuild", role.Permissions.ManageGuild.ToString() },
|
||||||
|
{ "Perm|ManageEmojis", role.Permissions.ManageEmojis.ToString() }
|
||||||
|
};
|
||||||
|
return new KeyValuePair<bool, Dictionary<string, string>>(true, settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, Dictionary<string, string>>(false, new Dictionary<string, string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
165
Core/Commands/DiscordAPI/Role_UpdatePerms.cs
Normal file
165
Core/Commands/DiscordAPI/Role_UpdatePerms.cs
Normal file
|
|
@ -0,0 +1,165 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_Role_UpdatePerms : CoreCommand_4arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number","Text" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Role id","CSV list of PermFlag=Bool" }; } }
|
||||||
|
public override string Helpfile { get { return "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 DiscordRoleGetSettings \n This command requires Discord full client mode enabled and connected"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
bool status = UpdateRolePerms(args).Result;
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(status, args[0], "see status for update state", CommandName);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GuildPermissions UpdateFlag(GuildPermissions NewPerms,string flag, bool flagValue)
|
||||||
|
{
|
||||||
|
switch (flag)
|
||||||
|
{
|
||||||
|
case "CreateInstantInvite":
|
||||||
|
NewPerms = NewPerms.Modify(flagValue);
|
||||||
|
break;
|
||||||
|
case "KickMembers":
|
||||||
|
NewPerms = NewPerms.Modify(null, flagValue);
|
||||||
|
break;
|
||||||
|
case "BanMembers":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "Administrator":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ManageChannels":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ManageGuild":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "AddReactions":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ViewAuditLog":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "SendTTSMessages":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "AttachFiles":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ReadMessageHistory":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "MentionEveryone":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "UseExternalEmojis":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "Connect":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "Speak":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "MuteMembers":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "UseVAD":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "MoveMembers":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "EmbedLinks":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "PrioritySpeaker":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "Stream":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ChangeNickname":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ManageNicknames":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ManageRoles":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "DeafenMembers":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ManageMessages":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ViewChannel":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "SendMessages":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ManageWebhooks":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
case "ManageEmojis":
|
||||||
|
NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return NewPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<bool> UpdateRolePerms(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(args[2], out ulong roleid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
SocketRole role = server.GetRole(roleid);
|
||||||
|
string[] bits = args[3].Split(',');
|
||||||
|
GuildPermissions NewPerms = role.Permissions;
|
||||||
|
foreach (String bit in bits)
|
||||||
|
{
|
||||||
|
string[] subbits = bit.Split('=');
|
||||||
|
if(subbits.Length == 2)
|
||||||
|
{
|
||||||
|
if(bool.TryParse(subbits[1],out bool flagValue) == true)
|
||||||
|
{
|
||||||
|
NewPerms = UpdateFlag(NewPerms, subbits[0], flagValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await role.ModifyAsync(Rp =>
|
||||||
|
{
|
||||||
|
Rp.Permissions = NewPerms;
|
||||||
|
}).ConfigureAwait(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
Core/Commands/DiscordAPI/TextChannels_List.cs
Normal file
49
Core/Commands/DiscordAPI/TextChannels_List.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Rest;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BSB.Commands.DiscordAPI
|
||||||
|
{
|
||||||
|
class Discord_TextChannels_List : CoreCommand_SmartReply_2arg
|
||||||
|
{
|
||||||
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number" }; } }
|
||||||
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id" }; } }
|
||||||
|
public override string Helpfile { get { return "Returns a list of text channels in a server \n collection is channelid: name"; } }
|
||||||
|
public override bool CallFunction(string[] args)
|
||||||
|
{
|
||||||
|
if (base.CallFunction(args) == true)
|
||||||
|
{
|
||||||
|
if (bot.discordReady() == false)
|
||||||
|
{
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName);
|
||||||
|
}
|
||||||
|
KeyValuePair<bool, Dictionary<string, string>> reply = ListTextChannels(args);
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "see status for state", CommandName, reply.Value);
|
||||||
|
}
|
||||||
|
return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected KeyValuePair<bool, Dictionary<string, string>> ListTextChannels(string[] args)
|
||||||
|
{
|
||||||
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
Dictionary<string, string> textChannels = new Dictionary<string, string>();
|
||||||
|
foreach(SocketTextChannel channel in server.TextChannels)
|
||||||
|
{
|
||||||
|
textChannels.Add(channel.Id.ToString(), channel.Name);
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, Dictionary<string, string>>(true, textChannels);
|
||||||
|
}
|
||||||
|
return new KeyValuePair<bool, Dictionary<string, string>>(false, new Dictionary<string, string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,17 +1,43 @@
|
||||||
using BetterSecondBotShared.logs;
|
using BetterSecondBotShared.logs;
|
||||||
|
using Discord.WebSocket;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Discord;
|
||||||
|
|
||||||
namespace BSB.bottypes
|
namespace BSB.bottypes
|
||||||
{
|
{
|
||||||
public abstract class VirtualsBot : Log2FileBot
|
public abstract class VirtualsBot : Log2FileBot
|
||||||
{
|
{
|
||||||
#region DiscordOutputTarget
|
#region DiscordOutputTarget
|
||||||
public virtual bool send_to_discord(string command,string message)
|
protected DiscordSocketClient DiscordLink = null;
|
||||||
|
protected string DiscordReadyWhyFailed = "";
|
||||||
|
public void setDiscordClient(DiscordSocketClient GivenDiscordLink)
|
||||||
{
|
{
|
||||||
return false;
|
DiscordLink = GivenDiscordLink;
|
||||||
|
}
|
||||||
|
public DiscordSocketClient getDiscordClient()
|
||||||
|
{
|
||||||
|
return DiscordLink;
|
||||||
|
}
|
||||||
|
public string getDiscordWhyFailed()
|
||||||
|
{
|
||||||
|
return DiscordReadyWhyFailed;
|
||||||
|
}
|
||||||
|
public bool discordReady()
|
||||||
|
{
|
||||||
|
if (DiscordLink == null)
|
||||||
|
{
|
||||||
|
DiscordReadyWhyFailed = "No client";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (DiscordLink.ConnectionState != ConnectionState.Connected)
|
||||||
|
{
|
||||||
|
DiscordReadyWhyFailed = "Not connected";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
public virtual Dictionary<UUID, string> GetIMChatWindowKeyNames()
|
public virtual Dictionary<UUID, string> GetIMChatWindowKeyNames()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue