From a80a616737623ad16c35bf65606738f2398bd9c8 Mon Sep 17 00:00:00 2001 From: Fax Date: Fri, 7 Apr 2023 14:29:29 +1200 Subject: [PATCH] update unfollow --- bot.js | 2 +- src/commands/modules/bind.js | 9 +- src/commands/modules/debugbork.js | 2 +- src/commands/modules/follow.js | 34 +- src/helpers/bot-stuff.js | 9 +- src/lang.json | 569 +++++++++++----------- src/models/Server.js | 61 +-- src/services/tts/AmazonTextToSpeechAPI.js | 20 +- 8 files changed, 357 insertions(+), 349 deletions(-) diff --git a/bot.js b/bot.js index 7212d2b..f796ca2 100644 --- a/bot.js +++ b/bot.js @@ -144,7 +144,7 @@ Common.error('rate limited'); Common.error(info); }); - bot.on('messageCreate', (replayed, shardID) => Common.error(`resume ${shardID}: ` + replayed)); + bot.on('shardResume', (replayed, shardID) => Common.error(`resume ${shardID}: ` + replayed)); bot.on('warn', (info) => Common.error('warn:' + info)); bot.on('shardReconnecting', (id) => Common.error(`Shard with ID ${id} reconnected.`)); diff --git a/src/commands/modules/bind.js b/src/commands/modules/bind.js index 261af2f..1fed9a8 100644 --- a/src/commands/modules/bind.js +++ b/src/commands/modules/bind.js @@ -88,6 +88,9 @@ class Bind extends Command { } else if (/^(permit)$/i.test(restriction_identifier)) { server.bindPermit = true; input.il8nResponse('bind.permit'); + } else if (/^(echo)$/i.test(restriction_identifier)) { + + input.response(JSON.stringify(server.bind)); } else if (input.args.length > 0) { const { mentions } = input.message; @@ -114,9 +117,11 @@ class Bind extends Command { const user = server.guild.members.cache.get(id); const channel = server.guild.channels.cache.get(id); const role = server.guild.roles.cache.get(id); - if (user || (channel && channel.type != 'voice') || role) continue; - if (!server.bind.includes(id)) server.bind.push(id); + console.log(channel.type); + if (user || channel?.isVoiceBased() !== true || role) continue; + + if (!server.bind.includes(id)) server.bind.push(id); } } diff --git a/src/commands/modules/debugbork.js b/src/commands/modules/debugbork.js index a387887..b05386b 100644 --- a/src/commands/modules/debugbork.js +++ b/src/commands/modules/debugbork.js @@ -47,7 +47,7 @@ function debug(msg) { if (server.isBound()) { active_server_count++; var chansize = 'no connection'; - if (server.connection) chansize = server.connection.channel.members.size; + if (server.connection) chansize = 0; //server.connection.channel.members.size; active_server_names += server.server_name + '(' + chansize + '): ' + build_permitted_string(server) + '\n'; } diff --git a/src/commands/modules/follow.js b/src/commands/modules/follow.js index 52f6436..8611732 100644 --- a/src/commands/modules/follow.js +++ b/src/commands/modules/follow.js @@ -32,7 +32,7 @@ async function follow(msg) { if (!member.voice.channel.joinable) return msg.il8nResponse('follow.permissions'); if (exceeded_daily_limit(server)) return msg.il8nResponse('follow.limitexceeded'); - + const errorFunc = (error) => { msg.il8nResponse('follow.error'); Common.error(error); @@ -40,9 +40,9 @@ async function follow(msg) { }; server.setMaster(member); - const connection = await server.joinVoiceChannel(member.voice.channel); - - if (!connection) { + await server.joinVoiceChannel(member.voice.channel); + + if (!server.connection) { msg.il8nResponse('follow.error'); server.release(); return; @@ -51,7 +51,7 @@ async function follow(msg) { server.addMemberSetting(member, 'toLanguage', 'default'); commands.notify('follow', { member: member, server: server }); msg.il8nResponse('follow.okay'); - + // unmute them if they're muted if (server.getMemberSetting(member, 'muted')) { server.addMemberSetting(member, 'muted', false); @@ -92,10 +92,10 @@ function should_pester(server) { * * */ function unfollow(msg) { var server = msg.server; - + if (server.connecting) return msg.il8nResponse('unfollow.connecting'); if (server.leaving) return msg.il8nResponse('unfollow.leaving'); - + if (!server.isBound()) { msg.il8nResponse('unfollow.none'); return; @@ -105,7 +105,7 @@ function unfollow(msg) { msg.il8nResponse('unfollow.nope'); return; } - + server.release(() => { commands.notify('unfollow', { member: msg.message.member, server: server }); @@ -151,9 +151,8 @@ function sidle(msg) { if ( !newMaster.voice || - !newMaster.voice.channel || - !server.guild.voice.connection || - newMaster.voice.channel.id != server.guild.voice.connection.channel.id + !server.connection || + newMaster.voice.channel.id != server.connection.joinConfig.channelId ) { msg.il8nResponse('sidle.novoice'); return; @@ -204,11 +203,8 @@ async function transfer(msg) { return; } - if ( - !newMaster.voice || - !newMaster.voice.channel || - (server.guild.voice.channel && newMaster.voice.channel.id != server.connection.channel.id) - ) { + let chanId = server?.connection?.joinConfig?.channelId; + if (chanId && newMaster?.voice?.channel?.id != chanId) { msg.il8nResponse('transfer.samevoice'); return; } @@ -219,14 +215,14 @@ async function transfer(msg) { } server.setMaster(newMaster); - if (server.guild.voice.connection) { + if (server.connection) { msg.il8nResponse('transfer.okay', { name: newMaster.displayName }); } else { var errorFunc = (err) => {}; - $connection = await server.joinVoiceChannel(newMaster.voice.channel); + await server.joinVoiceChannel(newMaster.voice.channel); - if (!$connection) { + if (!server.connection) { msg.il8nResponse('transfer.error'); server.release(); return; diff --git a/src/helpers/bot-stuff.js b/src/helpers/bot-stuff.js index 334af17..2217f1e 100644 --- a/src/helpers/bot-stuff.js +++ b/src/helpers/bot-stuff.js @@ -1,6 +1,6 @@ /*jshint esversion: 9 */ -const { Client, Events, GatewayIntentBits, PermissionsBitFieldBitField } = require('discord.js'), +const { Client, Events, GatewayIntentBits, PermissionsBitField } = require('discord.js'), auth = require('@auth'), Common = require('@helpers/common'), tl8 = require('@google-cloud/translate').v2; @@ -54,8 +54,11 @@ class BotStuff { let botMember = server.guild.members.cache.find((x) => x.id == this.bot.user.id); if (!botMember) return Common.error(new Error('Cant find the member object for this bot')); // something went wrong! - let rtn = botMember.hasPermission(PermissionsBitField.Flags.ManageMessages, false, true, true); - return rtn; + // member + + // let rtn = botMember.hasPermission(PermissionsBitField.Flags.ManageMessages, false, true, true); + + return botMember.permissions.has(PermissionsBitField.Flags.ManageMessages, true); } sendMessage(channel_id, message) { diff --git a/src/lang.json b/src/lang.json index 3a93d8c..84f812b 100644 --- a/src/lang.json +++ b/src/lang.json @@ -1,284 +1,285 @@ -{ - "en.general": { - "auto": ":key is now set to `default`. Talk bot will use the best or default settings for :key.", - "nope": "Sorry, only a server admin or server manager can do this.", - "okay": "Okay that worked! ☑" - }, - "en.set": { - "okay": "Set message for :lang", - "none": "no" - }, - "en.who": { - "okay": "My :title is :mymaster, :permitted", - "none": "I have no :title :~(", - "shorthelp": "Who is the current :title" - }, - "en.ping": { - "okay": "pong", - "shorthelp": "Test the bot is up" - }, - "en.follow": { - "join": "You need to join a voice channel before I can follow you!", - "okay": "Yes, :title!", - "huh": "Yes, :title?", - "nope": "Sorry, :name is my :title today. Get them to :command_charpermit you", - "shorthelp": "The bot will join your voice channel and speak what you write", - "connecting": "Cant follow, currently connecting to voice", - "leaving": "Cant follow until we've left voice", - "permissions": "I don't have permissions to join that voice channel", - "pester": "This server is using talkbot alot - consider installing talkbot yourself at " - }, - "en.defaults": { - "okay": "Your voice settings have been reset :D", - "shorthelp": "Reset your default voice settings" - }, - "en.unfollow": { - "okay": "Goodbye :title", - "okaypester": "Goodbye :title. This server is using talkbot alot - consider installing talkbot yourself at ", - "nope": "Sorry, you're not my :title.", - "none": "I have no :title... would you like to be my :title?", - "shorthelp": "Release the bot", - "connecting": "Cant unfollow, currently connecting to voice", - "leaving": "Cant unfollow, already leaving voice" - }, - "en.permit": { - "okay": "I'll listen to :name now", - "nope": "Sorry I can't do that, you're not my :title.", - "none": "I don't see any legit names", - "huh": "I don't know who :name is?", - "shorthelp": "Permit someone else to use the bot whilst it's following you" - }, - "en.unpermit": { - "okay": ":name talk to the hand", - "nope": "Sorry I can't do that, you're not my :title.", - "none": "I don't know who :name is?", - "deny": "Sorry I can't do that, you're not permitted.", - "shorthelp": "Unpermit someone else from using the bot" - }, - "en.leave": { - "nope": "Sorry I can't do that, you're not my :title." - }, - "en.join": { - "nope": "Sorry I can't do that, you're not my :title.", - "none": "You're not in a voice channel?" - }, - "en.myvoice": { - "okay": "OK, your personal voice is now :provider/:voice.", - "no": "Sorry, I cant find the voice :voice.", - "shorthelp": "Change accent or style.", - "more": "Your current voice is :provider/:voice. Run `:command_charlangs` to see the available langs, `:command_charvoices lang` to see the voices.", - "noped": "Your :command_charmyvoice setting has been overriden and you must use the command again to enable." - }, - "en.tolang": { - "okay": "OK, now translating to :lang.", - "deny": "Sorry, you're not permitted", - "nope": "Sorry, I dont have a voice for :lang", - "shorthelp": "Translate your text to a different language eg. en, fr, jp, de etc.", - "more": "You must specify a language code. You can find codes with `:command_charlangs`.\nTo stop translating use `:command_chartolang none`" - }, - "en.mypitch": { - "okay": "OK, your personal pitch is now :pitch.", - "deny": "Sorry, you're not permitted", - "shorthelp": "Alter the pitch of the bot's voice. Valid values are -20 to 20", - "usage": "Set the pitch the bot will speak with. Your current pitch is :pitch" - }, - "en.myspeed": { - "okay": "OK, your personal speed is now :speed.", - "deny": "Sorry, you're not permitted", - "shorthelp": "Alter the speed the bot talks. 1.0 is the default. Valid values are 0.25 to 4.0", - "usage": "Set the speed the bot will speak with. Your current speed is :speed" - }, - "en.sfx": { - "nope": "Sorry, only a server admin can set emojis", - "nosfx": "No SFX have been setup", - "okay": "Added sound effect for `:sfx_word`", - "notnotokay": "Removed sound effect for `:sfx_word`", - "clearallokay": "Removed all sound effects", - "none": "Cannot find sfx word: `:sfx_word`", - "noper": "options: [URL: play sfx] | [command url: make an audio emoji]", - "needshttps": "Sound URLs can only be https urls", - "needsWord": "Requires a [word/emoji] after \":sfx_command\" action", - "needsURL": "Requires https url after the [word/emoji] \":sfx_word\"", - "shorthelp": "Associate words or emojis with sound effects. :command_charsfx set [emoji] [audio file url]", - "nodelete": "You need to specify an action to perform such as set or del", - "usage": "Associate words or emojis with sound effect files" - }, - "en.sfxusage": { - "soundurl": "Add https sound Url to a word", - "list": "List all sounds on server", - "del": "Delete sound assinged to ", - "sfx": "Play Https Url without adding", - "clearall": "Clear all SFX" - }, - "en.sidle": { - "shorthelp": "Take control of the bot from someone else", - "nope": "You have to be an admin on this server to use this", - "okay": "Okay you're now the :title", - "none": "I have no :title", - "broken": "Something went wrong getting the voice channel, you might still have been made the :title" - }, - "en.transfer": { - "okay": "Okay :name is now the :title", - "nopermissions": "You need to have Manager Server permissions of be a server admin to do this.", - "args": "Doesnt look like you typed that command right", - "unknownnick": "I dont know this person", - "novoice": "I need to be in a voice channel first", - "samevoice": "My new :title has to be in the same channel first", - "broken": "Hmmm that didnt work on submit a bug on github at https://github.com/nullabork/talkbot", - "shorthelp": "Transfer control of the bot to another person", - "channelpermissions": "I don't have permission to join the voice channel for my new :title" - }, - "en.help": { - "shorthelp": "Show all the available commands. Get detailed help information using :command_charhelp [command]" - }, - "en.voices": { - "okay": "```css\n:table\n```\n You can set your voice with the `Voice` or the `Alias` values.\nFor example:\n`:command_charmyvoice sally`", - "shorthelp": "List of voices, `:command_charvoices au`", - "longhelp": "List of voices, `:command_charvoices au`", - "more": "You must specify a language code. eg `:command_charvoices au`.\nYou can find language codes with :command_charlangs" - }, - "en.textrule": { - "needsFind": "You need to provide a word to find", - "none": "Cannot find :find,\nTry copying the rule name from `:command_chartextrule list`, even the `\\` characters if there are any.", - "needsReplacement": "Your replacement value does not seem to be valid", - "nope": "Sorry you don't have permission to manage this server", - "addokay": "Rule for :find added", - "delokay": "Rule for :find deleted", - "norules": "No text replacement rules have been setup", - "clearallokay": "All rules cleared", - "shorthelp": "Add text replacement rules" - }, - "en.import": { - "imported": "Import complete", - "error": "Could not Import File. Try googling INI file fomat.", - "invalid": "Cannot find any valid data. current supports, :supports" - }, - "en.textruleusage": { - "title": "Text replacement rules", - "command": "Find and replace it with ", - "command_regex": "Find and replace it with using regular expressions", - "list": "List all rules", - "del": "Delete a rule by key", - "clearall": "Clear all rules" - }, - "en.details": { - "for": "voice settings for :user", - "none": "No voice settings for :user", - "shorthelp": "Get your's or others voice details" - }, - "en.mute": { - "unmuted": "Looks like you were muted, you have been unmuted.", - "okay": "I've muted :name", - "alreadymuted": ":name is already muted", - "shorthelp": "Mute yourself so your text is not read out" - }, - "en.unmute": { - "unmuted": "Looks like you were muted, you have been unmuted.", - "okay": "I've unmuted :name", - "alreadyunmuted": ":name is already unmuted", - "shorthelp": "Unmute yourself so all your text is read out" - }, - "en.tts": { - "notpermitted": "You have to be permitted to use this command", - "notinchannel": "Get the bot to follow you using :command_charfollow before using this command", - "shorthelp": "Speak when you're muted" - }, - "en.mytitle": { - "read": "I call you :title", - "set": "I'll now call you :title", - "shorthelp": "Set your personal title" - }, - "en.stop": { - "okay": "Stopped current message", - "okayAll": "Stopped **all** current messages", - "nope": "Sorry you need to be permitted or a server manager to stop voice", - "shorthelp": "Stop the current text from being read out" - }, - "en.restrict": { - "current": "The bot is currently restricted to :restrictions", - "usage": ":command_charrestrict none - allow talkbot to listen on all channels\n:command_charrestrict #channel - restrict talkbot to listen on #channel", - "nopermissions": "You need have Manage Server permissions to alter the channels Talkbot is restricted to", - "setdefault": "The bot will now listen on all channels", - "args": "Please include a channel eg. :command_charrestrict #channel", - "okay": "I'll only listen on these channels now: :channels", - "shorthelp": "Restrict talkbot to listen for freetext on specific channels" - }, - - "en.bind": { - "current": "The bot is currently bound to auto follow people in :bound channels", - "usage": ":command_charbind none - turn off auto follow\n :command_charbind #channel - auto follow to people who join channels: #channel\n:command_charbind permit|unpermit - auto permit in bound channels", - "nopermissions": "You need have Manage Server permissions to alter the channels Talkbot is restricted to", - "setdefault": "Not bound to any channel", - "args": "Please include a channel eg. :command_charbind #channel", - "okay": "I'll auto follow on these channels: :channels", - "shorthelp": "Bind talkbot to auto follow people who join specific channels", - "permit": "Permit any user who joins bound channels", - "unpermit": "Only follow the first person to join a bound channel" - }, - - "en.bindusage": { - "title": "Auto follow people in specific channels", - "description": "Auto following people who join channels: :bound.\n Auto permitting additional people is :permit.", - "noargs": "This output", - "none": "Turn auto follow off", - "channel": "Auto follow people who join specific channels", - "text_channel": "Auto follow people type in specific channels", - "username": "Auto follow specific people when they type in any channel", - "permit": "Permit any user who joins bound channels", - "unpermit": "Only follow the first person to join a bound channel" - }, - - "en.restrictusage": { - "title": "Restrict the channels to listen for text", - "description": "The bot is currently restricted to these channels :restrictions", - "noargs": "This output", - "none": "Allow the bot to listen on all channels", - "channels": "Restrict the bot to only listen on these channels" - }, - "en.keep": { - "usage": "You must include the number of messages to delete.\nUse `:command_charkeep all` OR `:command_charkeep `", - "keepAll": "I am now not deleting any messages\nUse `:command_charkeep ` to delete older messages.", - "keepCount": "I am now deleting messages older than the last **:count** messages.\nUse `:command_charkeep all` to not delete any messages.", - "all": "Okay I will now keep all messages and not delete any! ;)", - "shorthelp": "Specify how many messages to keep, the rest will be deleted.", - "nope": "You need have Manage Server permissions to alter the number of messages Talkbot keeps", - "msgpermissions": "The bot needs Manage Message permissions on the server to do this" - }, - "en.broadcast": { - "confirmation": "Confirmation Needed, Use :command_charbroadcast confirm" - }, - "en.announceme": { - "usage": ":command_charannounceme on/off. Your setting is :setting", - "announcejoin": "My :title, :name has :verb", - "announceleave": "My :title, :name has :verb", - "on": "Ok :title, you will now be announced when joining voice", - "off": "Ok :title, you will not be announced when joining voice" - }, - "en.myprefix": { - "usage": ":command_charmyprefix set [myprefix]\n:command_char myprefix on/off\nYour prefix is :setting", - "setokay": "Yes :title. I've set your prefix to :setting", - "on": "Ok :title, your voice will now prefix with :setting", - "off": "Ok :title, your voice will not be prefixed" - }, - "en.mysuffix": { - "usage": ":command_charmysuffix set [mysuffix]\n:command_char mysuffix on/off\nYour suffix is :setting", - "setokay": "Yes :title. I've set your suffix to :setting", - "on": "Ok :title, your voice will now suffix with :setting", - "off": "Ok :title, your voice will not be suffixed" - }, - "en.twitch": { - "usage": ":command_chartwitch permit [twitch_channel] [all, subs, mods, _username_]\n:command_chartwitch unpermit [twitch_channel] [all, subs, mods, _username_]", - "notbound": ":command_charfollow first before linking", - "notmaster": "Only my :title can link to twitch", - "permitchannel": "Please provide a twitch_channel eg. :advertise_streamer", - "permitwho": "Please provide a person or group to permit eg. [all, subs, mods, _username]", - "permitokay": "Permitted :who on ", - "unpermitokay": "Unpermitted :who on ", - "unpermitchannel": "Please provide a twitch_channel eg. :advertise_streamer", - "unpermitwho": "Please provide a person or group to unpermit eg. [all, subs, mods, _username]" - }, - "en.commandchar": { - "usage": ":command_charcommandchar [char] eg. !commandchar *", - "okay": "Command character changed to :command_char" - } -} +{ + "en.general": { + "auto": ":key is now set to `default`. Talk bot will use the best or default settings for :key.", + "nope": "Sorry, only a server admin or server manager can do this.", + "okay": "Okay that worked! ☑" + }, + "en.set": { + "okay": "Set message for :lang", + "none": "no" + }, + "en.who": { + "okay": "My :title is :mymaster, :permitted", + "none": "I have no :title :~(", + "shorthelp": "Who is the current :title" + }, + "en.ping": { + "okay": "pong", + "shorthelp": "Test the bot is up" + }, + "en.follow": { + "join": "You need to join a voice channel before I can follow you!", + "okay": "Yes, :title!", + "huh": "Yes, :title?", + "nope": "Sorry, :name is my :title today. Get them to :command_charpermit you", + "shorthelp": "The bot will join your voice channel and speak what you write", + "connecting": "Cant follow, currently connecting to voice", + "leaving": "Cant follow until we've left voice", + "permissions": "I don't have permissions to join that voice channel", + "pester": "This server is using talkbot alot - consider installing talkbot yourself at " + }, + "en.defaults": { + "okay": "Your voice settings have been reset :D", + "shorthelp": "Reset your default voice settings" + }, + "en.unfollow": { + "okay": "Goodbye :title", + "okaypester": "Goodbye :title. This server is using talkbot alot - consider installing talkbot yourself at ", + "nope": "Sorry, you're not my :title.", + "none": "I have no :title... would you like to be my :title?", + "shorthelp": "Release the bot", + "connecting": "Cant unfollow, currently connecting to voice", + "leaving": "Cant unfollow, already leaving voice" + }, + "en.permit": { + "okay": "I'll listen to :name now", + "nope": "Sorry I can't do that, you're not my :title.", + "none": "I don't see any legit names", + "huh": "I don't know who :name is?", + "shorthelp": "Permit someone else to use the bot whilst it's following you" + }, + "en.unpermit": { + "okay": ":name talk to the hand", + "nope": "Sorry I can't do that, you're not my :title.", + "none": "I don't know who :name is?", + "deny": "Sorry I can't do that, you're not permitted.", + "shorthelp": "Unpermit someone else from using the bot" + }, + "en.leave": { + "nope": "Sorry I can't do that, you're not my :title." + }, + "en.join": { + "nope": "Sorry I can't do that, you're not my :title.", + "none": "You're not in a voice channel?" + }, + "en.myvoice": { + "okay": "OK, your personal voice is now :provider/:voice.", + "no": "Sorry, I cant find the voice :voice.", + "shorthelp": "Change accent or style.", + "more": "Your current voice is :provider/:voice. Run `:command_charlangs` to see the available langs, `:command_charvoices lang` to see the voices.", + "noped": "Your :command_charmyvoice setting has been overriden and you must use the command again to enable." + }, + "en.tolang": { + "okay": "OK, now translating to :lang.", + "deny": "Sorry, you're not permitted", + "nope": "Sorry, I dont have a voice for :lang", + "shorthelp": "Translate your text to a different language eg. en, fr, jp, de etc.", + "more": "You must specify a language code. You can find codes with `:command_charlangs`.\nTo stop translating use `:command_chartolang none`" + }, + "en.mypitch": { + "okay": "OK, your personal pitch is now :pitch.", + "deny": "Sorry, you're not permitted", + "shorthelp": "Alter the pitch of the bot's voice. Valid values are -20 to 20", + "usage": "Set the pitch the bot will speak with. Your current pitch is :pitch" + }, + "en.myspeed": { + "okay": "OK, your personal speed is now :speed.", + "deny": "Sorry, you're not permitted", + "shorthelp": "Alter the speed the bot talks. 1.0 is the default. Valid values are 0.25 to 4.0", + "usage": "Set the speed the bot will speak with. Your current speed is :speed" + }, + "en.sfx": { + "nope": "Sorry, only a server admin can set emojis", + "nosfx": "No SFX have been setup", + "okay": "Added sound effect for `:sfx_word`", + "notnotokay": "Removed sound effect for `:sfx_word`", + "clearallokay": "Removed all sound effects", + "none": "Cannot find sfx word: `:sfx_word`", + "noper": "options: [URL: play sfx] | [command url: make an audio emoji]", + "needshttps": "Sound URLs can only be https urls", + "needsWord": "Requires a [word/emoji] after \":sfx_command\" action", + "needsURL": "Requires https url after the [word/emoji] \":sfx_word\"", + "shorthelp": "Associate words or emojis with sound effects. :command_charsfx set [emoji] [audio file url]", + "nodelete": "You need to specify an action to perform such as set or del", + "usage": "Associate words or emojis with sound effect files" + }, + "en.sfxusage": { + "soundurl": "Add https sound Url to a word", + "list": "List all sounds on server", + "del": "Delete sound assinged to ", + "sfx": "Play Https Url without adding", + "clearall": "Clear all SFX" + }, + "en.sidle": { + "shorthelp": "Take control of the bot from someone else", + "nope": "You have to be an admin on this server to use this", + "okay": "Okay you're now the :title", + "none": "I have no :title", + "broken": "Something went wrong getting the voice channel, you might still have been made the :title" + }, + "en.transfer": { + "okay": "Okay :name is now the :title", + "nopermissions": "You need to have Manager Server permissions of be a server admin to do this.", + "args": "Doesnt look like you typed that command right", + "unknownnick": "I dont know this person", + "novoice": "I need to be in a voice channel first", + "samevoice": "My new :title has to be in the same channel first", + "broken": "Hmmm that didnt work on submit a bug on github at https://github.com/nullabork/talkbot", + "shorthelp": "Transfer control of the bot to another person", + "channelpermissions": "I don't have permission to join the voice channel for my new :title" + }, + "en.help": { + "shorthelp": "Show all the available commands. Get detailed help information using :command_charhelp [command]" + }, + "en.voices": { + "okay": "```css\n:table\n```\n You can set your voice with the `Voice` or the `Alias` values.\nFor example:\n`:command_charmyvoice sally`", + "shorthelp": "List of voices, `:command_charvoices au`", + "longhelp": "List of voices, `:command_charvoices au`", + "more": "You must specify a language code. eg `:command_charvoices au`.\nYou can find language codes with :command_charlangs" + }, + "en.textrule": { + "needsFind": "You need to provide a word to find", + "none": "Cannot find :find,\nTry copying the rule name from `:command_chartextrule list`, even the `\\` characters if there are any.", + "needsReplacement": "Your replacement value does not seem to be valid", + "nope": "Sorry you don't have permission to manage this server", + "addokay": "Rule for :find added", + "delokay": "Rule for :find deleted", + "norules": "No text replacement rules have been setup", + "clearallokay": "All rules cleared", + "shorthelp": "Add text replacement rules" + }, + "en.import": { + "imported": "Import complete", + "error": "Could not Import File. Try googling INI file fomat.", + "invalid": "Cannot find any valid data. current supports, :supports" + }, + "en.textruleusage": { + "title": "Text replacement rules", + "command": "Find and replace it with ", + "command_regex": "Find and replace it with using regular expressions", + "list": "List all rules", + "del": "Delete a rule by key", + "clearall": "Clear all rules" + }, + "en.details": { + "for": "voice settings for :user", + "none": "No voice settings for :user", + "shorthelp": "Get your's or others voice details" + }, + "en.mute": { + "unmuted": "Looks like you were muted, you have been unmuted.", + "okay": "I've muted :name", + "alreadymuted": ":name is already muted", + "shorthelp": "Mute yourself so your text is not read out" + }, + "en.unmute": { + "unmuted": "Looks like you were muted, you have been unmuted.", + "okay": "I've unmuted :name", + "alreadyunmuted": ":name is already unmuted", + "shorthelp": "Unmute yourself so all your text is read out" + }, + "en.tts": { + "notpermitted": "You have to be permitted to use this command", + "notinchannel": "Get the bot to follow you using :command_charfollow before using this command", + "shorthelp": "Speak when you're muted" + }, + "en.mytitle": { + "read": "I call you :title", + "set": "I'll now call you :title", + "shorthelp": "Set your personal title" + }, + "en.stop": { + "okay": "Stopped current message", + "okayAll": "Stopped **all** current messages", + "nope": "Sorry you need to be permitted or a server manager to stop voice", + "shorthelp": "Stop the current text from being read out" + }, + "en.restrict": { + "current": "The bot is currently restricted to :restrictions", + "usage": ":command_charrestrict none - allow talkbot to listen on all channels\n:command_charrestrict #channel - restrict talkbot to listen on #channel", + "nopermissions": "You need have Manage Server permissions to alter the channels Talkbot is restricted to", + "setdefault": "The bot will now listen on all channels", + "args": "Please include a channel eg. :command_charrestrict #channel", + "okay": "I'll only listen on these channels now: :channels", + "shorthelp": "Restrict talkbot to listen for freetext on specific channels" + }, + + "en.bind": { + "current": "The bot is currently bound to auto follow people in :bound channels", + "usage": ":command_charbind none - turn off auto follow\n :command_charbind #channel - auto follow to people who join channels: #channel\n:command_charbind permit|unpermit - auto permit in bound channels", + "nopermissions": "You need have Manage Server permissions to alter the channels Talkbot is restricted to", + "setdefault": "Not bound to any channel", + "args": "Please include a channel eg. :command_charbind #channel", + "okay": "I'll auto follow on these channels: :channels", + "shorthelp": "Bind talkbot to auto follow people who join specific channels", + "permit": "Permit any user who joins bound channels", + "unpermit": "Only follow the first person to join a bound channel" + + }, + + "en.bindusage": { + "title": "Auto follow people in specific channels", + "description": "Auto following people who join channels: :bound.\n Auto permitting additional people is :permit.", + "noargs": "This output", + "none": "Turn auto follow off", + "channel": "Auto follow people who join specific channels", + "text_channel": "Auto follow people type in specific channels", + "username": "Auto follow specific people when they type in any channel", + "permit": "Permit any user who joins bound channels", + "unpermit": "Only follow the first person to join a bound channel" + }, + + "en.restrictusage": { + "title": "Restrict the channels to listen for text", + "description": "The bot is currently restricted to these channels :restrictions", + "noargs": "This output", + "none": "Allow the bot to listen on all channels", + "channels": "Restrict the bot to only listen on these channels" + }, + "en.keep": { + "usage": "You must include the number of messages to delete.\nUse `:command_charkeep all` OR `:command_charkeep `", + "keepAll": "I am now not deleting any messages\nUse `:command_charkeep ` to delete older messages.", + "keepCount": "I am now deleting messages older than the last **:count** messages.\nUse `:command_charkeep all` to not delete any messages.", + "all": "Okay I will now keep all messages and not delete any! ;)", + "shorthelp": "Specify how many messages to keep, the rest will be deleted.", + "nope": "You need have Manage Server permissions to alter the number of messages Talkbot keeps", + "msgpermissions": "The bot needs Manage Message permissions on the server to do this" + }, + "en.broadcast": { + "confirmation": "Confirmation Needed, Use :command_charbroadcast confirm" + }, + "en.announceme": { + "usage": ":command_charannounceme on/off. Your setting is :setting", + "announcejoin": "My :title, :name has :verb", + "announceleave": "My :title, :name has :verb", + "on": "Ok :title, you will now be announced when joining voice", + "off": "Ok :title, you will not be announced when joining voice" + }, + "en.myprefix": { + "usage": ":command_charmyprefix set [myprefix]\n:command_char myprefix on/off\nYour prefix is :setting", + "setokay": "Yes :title. I've set your prefix to :setting", + "on": "Ok :title, your voice will now prefix with :setting", + "off": "Ok :title, your voice will not be prefixed" + }, + "en.mysuffix": { + "usage": ":command_charmysuffix set [mysuffix]\n:command_char mysuffix on/off\nYour suffix is :setting", + "setokay": "Yes :title. I've set your suffix to :setting", + "on": "Ok :title, your voice will now suffix with :setting", + "off": "Ok :title, your voice will not be suffixed" + }, + "en.twitch": { + "usage": ":command_chartwitch permit [twitch_channel] [all, subs, mods, _username_]\n:command_chartwitch unpermit [twitch_channel] [all, subs, mods, _username_]", + "notbound": ":command_charfollow first before linking", + "notmaster": "Only my :title can link to twitch", + "permitchannel": "Please provide a twitch_channel eg. :advertise_streamer", + "permitwho": "Please provide a person or group to permit eg. [all, subs, mods, _username]", + "permitokay": "Permitted :who on ", + "unpermitokay": "Unpermitted :who on ", + "unpermitchannel": "Please provide a twitch_channel eg. :advertise_streamer", + "unpermitwho": "Please provide a person or group to unpermit eg. [all, subs, mods, _username]" + }, + "en.commandchar": { + "usage": ":command_charcommandchar [char] eg. !commandchar *", + "okay": "Command character changed to :command_char" + } +} diff --git a/src/models/Server.js b/src/models/Server.js index 888c8c1..4a885e4 100644 --- a/src/models/Server.js +++ b/src/models/Server.js @@ -13,7 +13,8 @@ const Lang = require('lang.js'), AudioPlayerStatus, createAudioPlayer, NoSubscriberBehavior, - getVoiceConnection + getVoiceConnection, + VoiceConnectionStatus } = require('@discordjs/voice'); const TextToSpeechService = require('@services/TextToSpeechService'); @@ -240,12 +241,20 @@ class Server { release(callback) { const server = this; - if (!server.guild.voice) return; + let i = 0; + // + // if (!server.guild.me.voice) return; + if (!server.connection) return; + if (server.leaving) return; // dont call it twice dude - if (callback) server.connection.on('disconnect', callback); + + if (callback) server.connection.on(VoiceConnectionStatus.Disconnected, callback); + commands.notify('leaveVoice', { server: server }); - server.connection.disconnect(); + + // server.connection.disconnect(); + server.connection.destroy(); } // get the server to join a voice channel @@ -255,11 +264,11 @@ class Server { if (server.connecting) return Common.error('joinVoiceChannel(' + voiceChannel.id + '): tried to connect twice!'); if (server.inChannel()) - return Common.error( + return Common.error( 'joinVoiceChannel(' + voiceChannel.id + '): already joined to ' + - server.connection.channel.id + + server.connection.joinConfig.channelId + '!', ); server.connecting = true; @@ -290,22 +299,22 @@ class Server { }); // when disconnect clear the master - note that d/c may happen without a closing event - server.connection.on('disconnect', () => { - server.stop('disconnect'); // stop playing - server.bound_to = null; - server.permitted = {}; - server.leaving = false; - }); + // server.connection.on(VoiceConnectionStatus.Disconnected, () => { + // console.log('disconnected'); + // server.stop('disconnect'); // stop playing + // server.bound_to = null; + // server.permitted = {}; + // server.leaving = false; + // }); // if an error occurs treat it like a d/c but capture the error // reset the state to as if there was no connection - server.connection.on('error', (error) => { + server.connection.on(VoiceConnectionStatus.Destroyed, (error) => { server.bound_to = null; server.permitted = {}; server.leaving = false; - server.connecting = false; // this might cause a race condition - Common.error(error); - server.connection.disconnect(); // nerf the connection because we got an error + server.connecting = false; // this might cause a race condition + // server.connection.disconnect(); // nerf the connection because we got an error }); server.connecting = false; @@ -319,18 +328,12 @@ class Server { // switch from whatever the current voice channel is to this voice channel async switchVoiceChannel(voiceChannel) { var server = this; - // if (!voiceChannel) return Common.error(new Error('null voiceChannel passed')); - // if (!server.connection) return await server.joinVoiceChannel(voiceChannel); - // if (voiceChannel.id == server.connection.channel.id) - // return Common.error('voiceChannel already joined'); + if (!voiceChannel) return Common.error(new Error('null voiceChannel passed')); + if (!server.connection) return await server.joinVoiceChannel(voiceChannel); + if (voiceChannel.id == server.connection.joinConfig.channelId) + return Common.error('voiceChannel already joined'); server.connection.rejoin({channelId: voiceChannel.id}); - - // joinVoiceChannel({ - // channelId: voiceChannel.id, - // guildId: server.guild.id, - // adapterCreator: server.guild.voiceAdapterCreator, - // }); } // permit another user to speak @@ -505,9 +508,9 @@ class Server { // stop currently playing audio and empty the audio queue (all=true) stop(reason, all) { - // if (all) { - // this.audioQueue = []; - // } + if (all) { + this.audioQueue = []; + } // if (this.connection && this.connection.dispatcher) // this.connection.dispatcher.end(reason); diff --git a/src/services/tts/AmazonTextToSpeechAPI.js b/src/services/tts/AmazonTextToSpeechAPI.js index ae74963..4825453 100644 --- a/src/services/tts/AmazonTextToSpeechAPI.js +++ b/src/services/tts/AmazonTextToSpeechAPI.js @@ -101,16 +101,16 @@ class AmazonTextToSpeechAPI extends TextToSpeechService { self.doBookkeeping(request); -let audioStream = await AmazonTextToSpeechAPI.polly.textToSpeech(request); -let thing = async () => { - return await ffmpegUtil.mp3ToReadableOpusBuffer(audioStream); -}; - -callback( - null, - thing -); - try { + try { + let audioStream = await AmazonTextToSpeechAPI.polly.textToSpeech(request); + + callback( + null, + async () => { + return await ffmpegUtil.mp3ToReadableOpusBuffer(audioStream); + } + ); + } catch (err) { Common.error(request); Common.error(err);