remove old discord bot type
This commit is contained in:
parent
497b14ad6f
commit
9d676df476
9 changed files with 3 additions and 893 deletions
|
|
@ -1,256 +0,0 @@
|
|||
using Discord;
|
||||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DiscordBotChannelControl : DiscordBotFunctions
|
||||
{
|
||||
|
||||
protected async Task SendMessageToChannelAsync(string channelname, string message, string catmapid, UUID sender_id, string TopicType)
|
||||
{
|
||||
if (AllowNewOutbound() == true)
|
||||
{
|
||||
|
||||
channelname = channelname.ToLowerInvariant();
|
||||
channelname = String.Concat(channelname.Where(char.IsLetterOrDigit));
|
||||
ITextChannel Channel = await FindTextChannel(channelname, catmap[catmapid], sender_id, TopicType).ConfigureAwait(false);
|
||||
if (Channel != null)
|
||||
{
|
||||
await Channel.SendMessageAsync(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<ITextChannel> FindTextChannel(string channelname, ICategoryChannel cat, UUID sender, string TopicType)
|
||||
{
|
||||
return await FindTextChannel(DiscordServer, channelname, cat, sender, TopicType);
|
||||
}
|
||||
|
||||
protected async Task<ITextChannel> FindTextChannel(IGuild onserver, string channelname)
|
||||
{
|
||||
return await FindTextChannel(onserver, channelname, null, UUID.Zero, "notUSED", false);
|
||||
}
|
||||
|
||||
protected async Task<ITextChannel> FindTextChannel(IGuild onserver,string channelname, ICategoryChannel cat, UUID sender, string TopicType,bool create_channel=true)
|
||||
{
|
||||
await WaitForUnlock().ConfigureAwait(false);
|
||||
channelname = channelname.ToLowerInvariant();
|
||||
channelname = String.Concat(channelname.Where(char.IsLetterOrDigit));
|
||||
DiscordLock = true;
|
||||
IReadOnlyCollection<ITextChannel> found_chans = await onserver.GetTextChannelsAsync(CacheMode.AllowDownload);
|
||||
ITextChannel result = null;
|
||||
foreach (ITextChannel ITC in found_chans)
|
||||
{
|
||||
if (create_channel == false)
|
||||
{
|
||||
if (ITC.Name == channelname)
|
||||
{
|
||||
result = ITC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ITC.CategoryId == cat.Id)
|
||||
{
|
||||
if (ITC.Name == channelname)
|
||||
{
|
||||
result = ITC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (create_channel == true)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
result = await CreateChannel(onserver, channelname, TopicType, sender.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await CleanDiscordChannel(result, 24).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
DiscordLock = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected async static Task CleanDiscordChannel(ITextChannel chan)
|
||||
{
|
||||
await CleanDiscordChannel(chan, 48).ConfigureAwait(false);
|
||||
}
|
||||
protected async static Task CleanDiscordChannel(ITextChannel chan, int HistoryHours)
|
||||
{
|
||||
await CleanDiscordChannel(chan, HistoryHours, false).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
protected async static Task CleanDiscordChannel(ITextChannel chan, int HistoryHours, bool forceempty)
|
||||
{
|
||||
long nowunix = DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||
IEnumerable<IMessage> messages;
|
||||
bool empty = false;
|
||||
while (empty == false)
|
||||
{
|
||||
empty = true;
|
||||
messages = await chan.GetMessagesAsync(50).FlattenAsync();
|
||||
List<ulong> deleteMessages = new List<ulong>();
|
||||
List<IMessage> slowDeleteMessages = new List<IMessage>();
|
||||
|
||||
foreach (IMessage mess in messages)
|
||||
{
|
||||
long messageunix = mess.Timestamp.ToUnixTimeSeconds();
|
||||
long dif = nowunix - messageunix;
|
||||
var hours = (dif / 60)/60;
|
||||
bool slowdel = false;
|
||||
|
||||
if (hours > (24 * 13))
|
||||
{
|
||||
slowdel = true;
|
||||
}
|
||||
if ((hours > HistoryHours) || (forceempty == true))
|
||||
{
|
||||
empty = false;
|
||||
if (slowdel == false)
|
||||
{
|
||||
deleteMessages.Add(mess.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
slowDeleteMessages.Add(mess);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((deleteMessages.Count > 0) || (slowDeleteMessages.Count > 0))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (deleteMessages.Count > 0)
|
||||
{
|
||||
await chan.DeleteMessagesAsync(deleteMessages).ConfigureAwait(true);
|
||||
}
|
||||
if (slowDeleteMessages.Count > 0)
|
||||
{
|
||||
foreach (IMessage slowdelmessage in slowDeleteMessages)
|
||||
{
|
||||
await chan.DeleteMessageAsync(slowdelmessage).ConfigureAwait(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
empty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<ITextChannel> CreateChannel(IGuild onserver, string channelname, string channeltopictype, string sender_id)
|
||||
{
|
||||
channelname = channelname.ToLowerInvariant();
|
||||
channelname = String.Concat(channelname.Where(char.IsLetterOrDigit));
|
||||
string display_topic = "" + channeltopictype + ":" + sender_id + "";
|
||||
if (channelname == "interface")
|
||||
{
|
||||
display_topic = "Actions -> !clear, !commands, !help command or command";
|
||||
}
|
||||
else if (channelname == "status")
|
||||
{
|
||||
display_topic = "Actions -> !clear";
|
||||
}
|
||||
else if (channelname == "localchat")
|
||||
{
|
||||
display_topic = "Actions -> !clear";
|
||||
}
|
||||
else if (sender_id == UUID.Zero.ToString())
|
||||
{
|
||||
display_topic = "" + myconfig.Basic_BotUserName + " #" + MyVersion + "";
|
||||
}
|
||||
else if (channeltopictype == "Group")
|
||||
{
|
||||
display_topic = "" + channeltopictype + ":" + sender_id + ": Actions -> !clear, !notice title|||message";
|
||||
}
|
||||
else if (channeltopictype == "IM")
|
||||
{
|
||||
display_topic = "" + channeltopictype + ":" + sender_id + ": Actions -> !clear, !close";
|
||||
}
|
||||
try
|
||||
{
|
||||
IGuildChannel channel = await onserver.CreateTextChannelAsync(channelname, X => DiscordGetNewChannelProperies(X, channelname, display_topic, channeltopictype.ToLowerInvariant()));
|
||||
ITextChannel Txtchan = await onserver.GetTextChannelAsync(channel.Id);
|
||||
return Txtchan;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DiscordGetNewChannelProperies(TextChannelProperties C, string channelname, string channeltopic, string catname)
|
||||
{
|
||||
if (catname != null)
|
||||
{
|
||||
if (catmap.ContainsKey(catname) == true)
|
||||
{
|
||||
C.CategoryId = catmap[catname].Id;
|
||||
}
|
||||
}
|
||||
C.Name = channelname;
|
||||
C.Topic = channeltopic;
|
||||
}
|
||||
|
||||
protected async Task DiscordRebuildChannels()
|
||||
{
|
||||
List<string> required_cats = new List<string>() { "bot", "group", "im" };
|
||||
IReadOnlyCollection<ICategoryChannel> found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload);
|
||||
foreach (ICategoryChannel fcat in found_cats)
|
||||
{
|
||||
if (required_cats.Contains(fcat.Name) == true)
|
||||
{
|
||||
required_cats.Remove(fcat.Name);
|
||||
catmap.Add(fcat.Name, fcat);
|
||||
}
|
||||
}
|
||||
foreach (string A in required_cats)
|
||||
{
|
||||
ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true);
|
||||
catmap.Add(A, newcat);
|
||||
}
|
||||
List<string> required_channels = new List<string>() { "status", "interface","localchat" };
|
||||
IReadOnlyCollection<ITextChannel> found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload);
|
||||
List<string> GroupChannels = new List<string>();
|
||||
foreach (ITextChannel chan in found_chans)
|
||||
{
|
||||
if (chan.CategoryId == catmap["bot"].Id)
|
||||
{
|
||||
required_channels.Remove(chan.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (chan.CategoryId == catmap["group"].Id)
|
||||
{
|
||||
GroupChannels.Add(chan.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (string A in required_channels)
|
||||
{
|
||||
_ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false);
|
||||
}
|
||||
foreach (Group G in mygroups.Values)
|
||||
{
|
||||
string groupname = G.Name.ToLowerInvariant();
|
||||
groupname = String.Concat(groupname.Where(char.IsLetterOrDigit));
|
||||
if (GroupChannels.Contains(groupname) == false)
|
||||
{
|
||||
_ = await FindTextChannel(groupname, catmap["group"], G.ID, "Group").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenMetaverse;
|
||||
using Discord;
|
||||
using BetterSecondBotShared.Static;
|
||||
using Discord.WebSocket;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DiscordBot : DiscordBotInbound
|
||||
{
|
||||
protected override void AfterBotLoginHandler()
|
||||
{
|
||||
_ = DiscordBotAfterLogin();
|
||||
base.AfterBotLoginHandler();
|
||||
}
|
||||
protected virtual async Task DiscordBotAfterLogin()
|
||||
{
|
||||
if (reconnect == false)
|
||||
{
|
||||
if (helpers.notempty(myconfig.DiscordFull_Token) == false)
|
||||
{
|
||||
myconfig.DiscordFull_Enable = false;
|
||||
}
|
||||
else if (myconfig.DiscordFull_ServerID <= 0)
|
||||
{
|
||||
myconfig.DiscordFull_Enable = false;
|
||||
}
|
||||
if (myconfig.DiscordFull_Enable == false)
|
||||
{
|
||||
if (helpers.notempty(myconfig.DiscordRelay_URL) == true)
|
||||
{
|
||||
if (helpers.notempty(myconfig.DiscordRelay_GroupUUID) == true)
|
||||
{
|
||||
if (UUID.TryParse(myconfig.DiscordRelay_GroupUUID, out UUID targetgroup) == true)
|
||||
{
|
||||
if (targetgroup != UUID.Zero)
|
||||
{
|
||||
discord_group_relay = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordClient = new DiscordSocketClient();
|
||||
DiscordClient.Ready += DiscordClientReady;
|
||||
DiscordClient.LoggedOut += DiscordClientLoggedOut;
|
||||
DiscordClient.MessageReceived += DiscordClientMessageReceived;
|
||||
await DiscordClient.LoginAsync(TokenType.Bot, myconfig.DiscordFull_Token);
|
||||
_ = DiscordClient.StartAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual async Task<Task> DiscordClientReady()
|
||||
{
|
||||
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
||||
if (DiscordServer != null)
|
||||
{
|
||||
DiscordUnixTimeOnine = helpers.UnixTimeNow();
|
||||
DiscordClientConnected = true;
|
||||
await DiscordRebuildChannels();
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordClientConnected = false;
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
using BetterSecondBotShared.Static;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DiscordBotFunctions : Values
|
||||
{
|
||||
protected Task WaitForUnlock()
|
||||
{
|
||||
while (DiscordLock == true)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
protected bool AllowNewOutbound()
|
||||
{
|
||||
if (DiscordUnixTimeOnine != 0)
|
||||
{
|
||||
long dif = helpers.UnixTimeNow() - DiscordUnixTimeOnine;
|
||||
if (dif > 8)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected Task DiscordClientLoggedOut()
|
||||
{
|
||||
DiscordClientConnected = false;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task DiscordKillMePlease()
|
||||
{
|
||||
DiscordUnixTimeOnine = 0;
|
||||
await DiscordClient.LogoutAsync();
|
||||
}
|
||||
|
||||
public override void KillMePlease()
|
||||
{
|
||||
base.KillMePlease();
|
||||
if (DiscordClient != null)
|
||||
{
|
||||
_ = DiscordKillMePlease();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,260 +0,0 @@
|
|||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DiscordBotInbound : DiscordBotRelay
|
||||
{
|
||||
protected async Task<Task> InboundLocalchatMessage(SocketMessage message)
|
||||
{
|
||||
IGuildUser user = (IGuildUser)message.Author;
|
||||
Client.Self.Chat(message.Content, 0, ChatType.Normal);
|
||||
return await MarkMessage(message, "✅");
|
||||
}
|
||||
protected async Task<Task> InboundInterfaceMessage(SocketMessage message)
|
||||
{
|
||||
StringBuilder output = new StringBuilder();
|
||||
if (message.Content.StartsWith("!"))
|
||||
{
|
||||
if (message.Content == "!commands")
|
||||
{
|
||||
int counter = 0;
|
||||
string addon = "";
|
||||
foreach (string a in CommandsInterface.GetCommandsList())
|
||||
{
|
||||
output.Append(addon);
|
||||
addon = " , ";
|
||||
output.Append(a);
|
||||
counter++;
|
||||
if (counter == 5)
|
||||
{
|
||||
output.Append("\n");
|
||||
addon = "";
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot");
|
||||
}
|
||||
else if (message.Content.StartsWith("!help") == true)
|
||||
{
|
||||
string[] bits = message.Content.Split(' ');
|
||||
if (bits.Length == 2)
|
||||
{
|
||||
string command = bits[1].ToLowerInvariant();
|
||||
|
||||
if (CommandsInterface.GetCommandsList().Contains(command) == true)
|
||||
{
|
||||
output.Append("\n=========================\nCommand:");
|
||||
output.Append(command);
|
||||
output.Append("\n");
|
||||
output.Append("Workspace: ");
|
||||
output.Append(CommandsInterface.GetCommandWorkspace(command));
|
||||
output.Append("\n");
|
||||
output.Append("Min args: ");
|
||||
output.Append(CommandsInterface.GetCommandArgs(command).ToString());
|
||||
output.Append("\n");
|
||||
output.Append("Arg types: ");
|
||||
output.Append(String.Join(",", CommandsInterface.GetCommandArgTypes(command)));
|
||||
output.Append("\n");
|
||||
output.Append("\n");
|
||||
output.Append("About: ");
|
||||
output.Append(CommandsInterface.GetCommandHelp(command));
|
||||
await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot");
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Append("Unable to find command: ");
|
||||
output.Append(command);
|
||||
output.Append(" please use !commands for a full list");
|
||||
await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await SendMessageToChannelAsync("interface", "Please format help request as follows: !help commandname", "bot", UUID.Zero, "bot");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Append("Unknown request: ");
|
||||
output.Append(message.Content);
|
||||
await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] bits = message.Content.Split("|||");
|
||||
string command = bits[0].ToLowerInvariant();
|
||||
bool known_command = CommandsInterface.GetCommandsList().Contains(command);
|
||||
if(known_command == false)
|
||||
{
|
||||
known_command = custom_commands.ContainsKey(command);
|
||||
}
|
||||
if (known_command == true)
|
||||
{
|
||||
bool process_status = false;
|
||||
if(bits.Length == 1)
|
||||
{
|
||||
bits = new string[] { bits[0], "" };
|
||||
}
|
||||
if (custom_commands.ContainsKey(command) == false)
|
||||
{
|
||||
process_status = CommandsInterface.Call(command, bits[1], UUID.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
process_status = true;
|
||||
Thread t = new Thread(() => custom_commands_loop(command, bits[1], UUID.Zero));
|
||||
t.Start();
|
||||
}
|
||||
if (process_status == true)
|
||||
{
|
||||
await MarkMessage(message, "✅").ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await MarkMessage(message, "❌").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Append("Unable to find command: ");
|
||||
output.Append(command);
|
||||
output.Append(" please use !commands for a full list");
|
||||
await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot");
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
protected virtual async Task<Task> InboundImMessage(ITextChannel Chan, SocketMessage message)
|
||||
{
|
||||
if (message.Content.StartsWith("!close"))
|
||||
{
|
||||
await Chan.DeleteAsync();
|
||||
}
|
||||
else if (message.Content.StartsWith("!clear"))
|
||||
{
|
||||
await CleanDiscordChannel(Chan, 0, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] bits = Chan.Topic.Split(':');
|
||||
if (bits.Length >= 2)
|
||||
{
|
||||
if (bits[0] == "IM")
|
||||
{
|
||||
if (UUID.TryParse(bits[1], out UUID avatar) == true)
|
||||
{
|
||||
IGuildUser user = (IGuildUser)message.Author;
|
||||
Client.Self.InstantMessage(avatar, message.Content);
|
||||
await MarkMessage(message, "✅");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task<Task> InboundGroupImMessage(ITextChannel Chan, SocketMessage message)
|
||||
{
|
||||
string[] bits = Chan.Topic.Split(':');
|
||||
if (bits.Length >= 2)
|
||||
{
|
||||
if (bits[0] == "Group")
|
||||
{
|
||||
if (UUID.TryParse(bits[1], out UUID group) == true)
|
||||
{
|
||||
if (mygroups.ContainsKey(group) == true)
|
||||
{
|
||||
if (message.Content == "!clear")
|
||||
{
|
||||
await CleanDiscordChannel(Chan, 0, true).ConfigureAwait(false);
|
||||
}
|
||||
else if (message.Content.StartsWith("!notice") == true)
|
||||
{
|
||||
string Noticetitle = "Notice";
|
||||
string Noticemessage;
|
||||
bits = message.Content.Split("|||", StringSplitOptions.None);
|
||||
if (bits.Length == 2)
|
||||
{
|
||||
Noticetitle = bits[0];
|
||||
Noticemessage = bits[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
Noticemessage = bits[0];
|
||||
}
|
||||
Noticetitle = Noticetitle.Replace("!notice ", "");
|
||||
Noticetitle = Noticetitle.Trim();
|
||||
CommandsInterface.Call("GroupNotice", "" + group.ToString() + "~#~" + Noticetitle + "~#~" + Noticemessage, UUID.Zero);
|
||||
await MarkMessage(message, "✅");
|
||||
}
|
||||
else
|
||||
{
|
||||
IGuildUser user = (IGuildUser)message.Author;
|
||||
CommandsInterface.Call("Groupchat", "" + group.ToString() + "~#~" + message.Content, UUID.Zero);
|
||||
await MarkMessage(message, "✅");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task<Task> MarkMessage(SocketMessage message,string emote)
|
||||
{
|
||||
var Tickmark = new Emoji(emote);
|
||||
await message.AddReactionAsync(Tickmark, RequestOptions.Default);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task<Task> DiscordClientMessageReceived(SocketMessage message)
|
||||
{
|
||||
if (AllowNewOutbound() == true)
|
||||
{
|
||||
if (message.Author.IsBot == false)
|
||||
{
|
||||
if (Client.Network.Connected == false)
|
||||
{
|
||||
await message.DeleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ITextChannel Chan = (ITextChannel)message.Channel;
|
||||
if (message.Content.StartsWith("!clear") == true)
|
||||
{
|
||||
await CleanDiscordChannel(Chan, 0, true).ConfigureAwait(false);
|
||||
}
|
||||
else if (Chan.CategoryId == catmap["bot"].Id)
|
||||
{
|
||||
if (Chan.Name == "interface")
|
||||
{
|
||||
await InboundInterfaceMessage(message).ConfigureAwait(false);
|
||||
}
|
||||
else if(Chan.Name == "localchat")
|
||||
{
|
||||
await InboundLocalchatMessage(message).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else if (Chan.CategoryId == catmap["im"].Id)
|
||||
{
|
||||
await InboundImMessage(Chan, message).ConfigureAwait(false);
|
||||
}
|
||||
else if (Chan.CategoryId == catmap["group"].Id)
|
||||
{
|
||||
await InboundGroupImMessage(Chan, message).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
using OpenMetaverse;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DiscordBotStatus : DiscordBotChannelControl
|
||||
{
|
||||
protected void DiscordStatusUpdate()
|
||||
{
|
||||
if (AllowNewOutbound() == true)
|
||||
{
|
||||
if (LastSendDiscordStatus != LastStatusMessage)
|
||||
{
|
||||
LastSendDiscordStatus = LastStatusMessage;
|
||||
_ = SendMessageToChannelAsync("status", LastSendDiscordStatus, "bot", UUID.Zero, "bot");
|
||||
}
|
||||
}
|
||||
}
|
||||
string DiscordBotStatus_laststatus = "";
|
||||
public override string GetStatus()
|
||||
{
|
||||
string reply = "";
|
||||
if (myconfig.DiscordFull_Enable == true)
|
||||
{
|
||||
if (DiscordClientConnected == true)
|
||||
{
|
||||
reply = "[Discord: connected]";
|
||||
DiscordStatusUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
reply = "[Discord: Disconnected]";
|
||||
}
|
||||
}
|
||||
else if (discord_group_relay == true)
|
||||
{
|
||||
reply = " [Discord: Group Relay]";
|
||||
}
|
||||
if (reply != "")
|
||||
{
|
||||
reply = " " + reply;
|
||||
}
|
||||
if (reply != DiscordBotStatus_laststatus)
|
||||
{
|
||||
DiscordBotStatus_laststatus = reply;
|
||||
return base.GetStatus() + reply;
|
||||
}
|
||||
return base.GetStatus();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class Values : ChatRelay
|
||||
{
|
||||
protected bool discord_group_relay;
|
||||
protected DiscordSocketClient DiscordClient;
|
||||
protected bool DiscordClientConnected;
|
||||
protected IGuild DiscordServer;
|
||||
protected string LastSendDiscordStatus = "";
|
||||
protected long DiscordUnixTimeOnine;
|
||||
protected bool DiscordLock;
|
||||
|
||||
protected Dictionary<string, ICategoryChannel> catmap = new Dictionary<string, ICategoryChannel>();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
using BetterSecondBotShared.Static;
|
||||
using Discord.Webhook;
|
||||
using OpenMetaverse;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DiscordBotRelay : DiscordBotStatus
|
||||
{
|
||||
public override void SendIM(UUID avatar, string message)
|
||||
{
|
||||
base.SendIM(avatar, message);
|
||||
if (AvatarKey2Name.ContainsKey(avatar) == true)
|
||||
{
|
||||
if (DiscordClientConnected == true)
|
||||
{
|
||||
_ = SendMessageToChannelAsync(AvatarKey2Name[avatar], "Bot/Script: " + message + "", "im", avatar, "IM").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected async Task DiscordGroupMessage(UUID group_uuid, string sender_name, string message)
|
||||
{
|
||||
if ((helpers.notempty(sender_name) == true) && (helpers.notempty(message) == true))
|
||||
{
|
||||
if (mygroups.ContainsKey(group_uuid) == true)
|
||||
{
|
||||
await SendMessageToChannelAsync(mygroups[group_uuid].Name, "" + sender_name + ": " + message + "", "group", group_uuid, "Group").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected virtual async Task DiscordIMMessage(UUID sender_uuid, string sender_name, string message)
|
||||
{
|
||||
if ((helpers.notempty(sender_name) == true) && (helpers.notempty(message) == true))
|
||||
{
|
||||
await SendMessageToChannelAsync(sender_name, "" + sender_name + ": " + message + "", "im", sender_uuid, "IM").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
protected async override void BotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme)
|
||||
{
|
||||
base.BotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme);
|
||||
await DiscordBotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override string CommandHistoryAdd(string command, string arg, bool status, string WhyFailed)
|
||||
{
|
||||
string output = base.CommandHistoryAdd(command, arg, status, WhyFailed);
|
||||
if (output != "")
|
||||
{
|
||||
_ = SendMessageToChannelAsync("interface", output, "bot", UUID.Zero, "bot");
|
||||
}
|
||||
return output;
|
||||
}
|
||||
protected async Task<Task> DiscordBotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme)
|
||||
{
|
||||
if (fromme == false)
|
||||
{
|
||||
if (discord_group_relay == true)
|
||||
{
|
||||
// GroupChat Relay only
|
||||
if (group == true)
|
||||
{
|
||||
if (myconfig.DiscordRelay_URL != "")
|
||||
{
|
||||
if ((myconfig.DiscordRelay_GroupUUID == group_uuid.ToString()) || (myconfig.DiscordRelay_GroupUUID == "*") || (myconfig.DiscordRelay_GroupUUID == "all"))
|
||||
{
|
||||
Group Gr = mygroups[group_uuid];
|
||||
try
|
||||
{
|
||||
using var DWHclient = new DiscordWebhookClient(myconfig.DiscordRelay_URL);
|
||||
string SendMessage = "(" + Gr.Name + ") @" + sender_name + ":" + message + "";
|
||||
await DWHclient.SendMessageAsync(text: SendMessage).ConfigureAwait(false);
|
||||
DWHclient.Dispose();
|
||||
}
|
||||
catch {
|
||||
Info("Discord web hook has failed - marking as disabled untill next restart!");
|
||||
myconfig.DiscordRelay_URL = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (DiscordClientConnected == true)
|
||||
{
|
||||
if (avatar == true)
|
||||
{
|
||||
if (localchat == false)
|
||||
{
|
||||
if (group == true)
|
||||
{
|
||||
Debug("DiscordBotChatControler - GroupChat:("+ group_uuid.ToString()+" -> " + sender_name + ":" + message);
|
||||
await DiscordGroupMessage(group_uuid, sender_name, message).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug("DiscordBotChatControler - IM:" + sender_name + ":" + message);
|
||||
await DiscordIMMessage(sender_uuid, sender_name, message).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug("DiscordBotChatControler - Localchat:" + sender_name + ":" + message);
|
||||
await SendMessageToChannelAsync("localchat", "" + sender_name + ":" + message, "bot", UUID.Zero, "bot").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug("DiscordBotChatControler - Not from an avatar");
|
||||
}
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenMetaverse;
|
||||
using Discord;
|
||||
using BetterSecondBotShared.Static;
|
||||
using Discord.WebSocket;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DiscordBotTTS : DiscordBot
|
||||
{
|
||||
protected ITextChannel TTSchannel;
|
||||
protected IGuild TTSDiscordServer;
|
||||
protected override async Task<Task> DiscordClientReady()
|
||||
{
|
||||
await base.DiscordClientReady();
|
||||
TTSDiscordServer = DiscordClient.GetGuild(myconfig.DiscordTTS_server_id);
|
||||
if (TTSDiscordServer != null)
|
||||
{
|
||||
IGuildUser user = await TTSDiscordServer.GetCurrentUserAsync();
|
||||
await user.ModifyAsync(x => {
|
||||
x.Nickname = myconfig.DiscordTTS_Nickname;
|
||||
});
|
||||
FindTTsChannel();
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async void FindTTsChannel()
|
||||
{
|
||||
if (myconfig.DiscordTTS_Enable == true)
|
||||
{
|
||||
TTSchannel = await FindTextChannel(TTSDiscordServer, myconfig.DiscordTTS_channel_name);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task DiscordIMMessage(UUID sender_uuid, string sender_name, string message)
|
||||
{
|
||||
await base.DiscordIMMessage(sender_uuid, sender_name, message);
|
||||
if (myconfig.DiscordTTS_Enable == true)
|
||||
{
|
||||
if ((helpers.notempty(sender_name) == true) && (helpers.notempty(message) == true))
|
||||
{
|
||||
if (sender_uuid.ToString() == myconfig.DiscordTTS_avatar_uuid)
|
||||
{
|
||||
if (TTSchannel == null)
|
||||
{
|
||||
FindTTsChannel();
|
||||
}
|
||||
if (TTSchannel != null)
|
||||
{
|
||||
await TTSchannel.SendMessageAsync(message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
SecondBot -> DialogsBot -> DiscordBotTTS -> DiscordBot -> DiscordBotInbound ->
|
||||
DiscordBotRelay -> DiscordBotStatus -> DiscordBotChannelControl ->
|
||||
DiscordBotFunctions -> Values -> ChatRelay -> RLVbot -> RLVbotHelper ->
|
||||
AwaitReplyEventBot -> CommandsBot -> AVstorageBot -> AtHome ->
|
||||
MessageSwitcherBot -> EventsBot -> VoidEventBot -> AnimationsBot ->
|
||||
SecondBot -> DialogsBot -> ChatRelay -> RLVbot -> RLVbotHelper ->
|
||||
AwaitReplyEventBot -> CommandsBot -> AVstorageBot -> AtHome ->
|
||||
MessageSwitcherBot -> EventsBot -> VoidEventBot -> AnimationsBot ->
|
||||
VirtualsBot -> Log2FileBot -> ActionsAutoAcceptBot -> BasicBot
|
||||
Loading…
Reference in a new issue