#TeleLink 1.1 skript by DereWah -> https://www.spigotmc.org/resources/telelink-link-a-minecraft-account-to-telegram-with-skript.109675 Options: p: &7[&bT&9L&7] #bot prefix bot_user: SkriptItaly_bot #username of the bot bot_token: TOKEN auto_auth: true #authorize the bot on skript reload? server_ip: your.server.ip #your server IP, aesthetic purposes server_website1: https://t.me/SkriptItaly #change this to any social you have server_button1: đŸ‘Ĩ CHANNEL đŸ‘Ĩ #button text for website above server_website2: https://www.spigotmc.org/resources/skelegram-the-skript-telegram-addon.109653/ #change this to anything you want server_button2: 👨‍đŸ’ģ CREDITS 👨‍đŸ’ģ #button text for website above 2fa_cooldown: 60 seconds #expiry for a 2fa request 2fa_session_length: 10 minutes #length of authorization from 2fa credits: true #------- COMMANDS ------- #/telelink | telelink.use | main command #/telelink link | telelink.use | begin linking your account. #/telelink unlink | telelink.use | unlink your account. #/telelink forceunlink | telelink.admin | forcefully unlink a player's account. #/telelink stop | telelink.admin | stop the bot #/telelink start | telelink.admin | start the bot #/telelink reset | telelink.admin | reset all the variables and linked users. #/telelink 2fa | telelink.2fa | Verify yourself via your telegram account. After verification is complete, the function is2FAAuthorized(p: offlineplayer) returns true, for a set amount of time (session duration, in options). #/telelink view | telelink.view | view another user's linked telegram account. #------------------------ #------ FUNCTIONS ------- #You may use the following functions to automatically get a player's TG account on the server. This is useful to quickly build a bot without having to register every user, as this already does the work you. #getLinkedMinecraft(id: text) | Get the linked minecraft account of a telegram ID of a user. The ID has to be a text, as Skript can't handle long numbers (and IDs are really long numbers) #getBotUser() | Get the username of the bot that is running TeleLink. TeleLink can only run 1 bot at a time, but a server may be running multiple different bots, so in order to send messages on commands or outside of telegram events you need to specify a bot name. #getTelegramID(p: offlineplayer) | Get the unique Telegram ID of a player, if they have linked an account. Otherwise null. #getTelegramUsername(p: player) | Get the username of a player. Use this just for aesthetics, DON't RELY ON THIS! It may be null or could even not correspond to the player's updated username, as they can change it. USE getTelegramID instead!! #is2FAAuthorized(p: offlineplayer) | Use this function to check if a player has recently verified themselves with TeleLink's 2FA. Use this along with an else condition telling the player to verify themselves with /telelink 2fa, so they know how they can verify. #------------------------ #For issues, contact me on telegram @DereWah or on Discord @DereWah#8414 or on spigot. on load: if {@auto_auth} is true: send message "{@p} &b&oAuthorizing the bot..." to console telegram login to bot "{@bot_user}" with token "{@bot_token}" send message "{@p} &b&oCompleted." to console loop indexes of {telelink::2fa::*}: send message "{@p} &cYour 2FA session expired." to loop-value parsed as player clear {telelink::2fa::*} function genTGCode() :: integer: set {_code} to a random integer between 100000 and 999999 while indexes of {telelink::codes::*} contains {_code}: set {_code} to a random integer between 100000 and 999999 return {_code} function welcomeMessage() :: telegram message: set {_welcome} to a new telegram message with text "Welcome on 📱 {@bot_user} 📱%nl%%nl%You can use this 🤖 bot to link your minecraft account on 🎮 {@server_ip}!%nl%%nl%🎮 To get a code, type /telelink in minecraft." set {_b1} to a new inline button with text "{@server_button1}" with url "{@server_website1}" set {_b2} to a new inline button with text "{@server_button2}" with url "{@server_website2}" set {_kb} to a new inline keyboard with buttons {_b1} and {_b2} set inline keyboard of {_welcome} to {_kb} #you can customize this welcome message as you please. return {_welcome} on telegram message: if "%event-telegram bot%" is "{@bot_user}": if text of event-telegram message is "/start": send telegram message welcomeMessage() to sender of event-telegram message else if text of event-telegram message contains "/telelink": if {telelink::telegram::%id of sender of event-telegram message%} is not set: set {_args::*} to text of event-telegram message split at " " if {_args::2} parsed as integer is set: set {_code} to {_args::2} parsed as integer if indexes of {telelink::codes::*} contains "%{_code}%": set {_p} to {telelink::codes::%{_code}%} if {telelink::users::%{_p}%::userid} is not set: set {_id} to id of sender of event-telegram message set {telelink::users::%{_p}%::userid} to {_id} set {telelink::telegram::%{_id}%} to {_p} set {telelink::users::%{_p}%::username} to "%sender of event-telegram message%" clear {telelink::codes::%{_code}%} clear {telelink::users::%{_p}%::code} send message "{@p} &bYou have linked your telegram account %{telelink::users::%{_p}%::username}%!" to {_p} reply to telegram message event-telegram message with "🎮 Minecraft account %{_p}% succesfully linked!" else: reply to telegram message event-telegram message with "This user is already linked to another account." clear {telelink::codes::%{_code}%} else: reply to telegram message event-telegram message with "Invalid code: %{_code}%%nl%%nl%Please try generating a new one in minecraft with /telelink link or contact an admin if the error persists." else: reply to telegram message event-telegram message with "Invalid code: %{_args::2}%" else: reply to telegram message event-telegram message with "⚠ī¸ Your account is already linked to 🎮%{telelink::telegram::%id of sender of event-telegram message%}%!%nl%%nl%Use /telelink unlink in game to unlink." command /telelink [] [] [] []: aliases: /tl, /telelink, /telegram permission: telelink.use trigger: if arg-1 is "login" or "auth" or "start" or "authbot": if player has permission "telelink.admin": send message "{@p} &b&oAuthorizing the bot..." telegram login to bot "{@bot_user}" with token "{@bot_token}" send message "{@p} &b&oCompleted. If you experience any issues, check the console for more info." else: send message "{@p} &cYou don't have the permission &4telelink.admin&c." else if arg-1 is "stop" or "clearsession" or "logout": if player has permission "telelink.admin": send message "{@p} &b&oStopping session... This may take up to 50 seconds. To prevent bugs, please wait for the confirmation message before using the skript again." clear telegram session of bot "{@bot_user}" send message "{@p} &b&oSession stopped. If you experience any issues, check the console for more info." else: send message "{@p} &cYou don't have the permission &4telelink.admin&c." else if arg-1 is "link": if {telelink::users::%player%::userid} is not set: #remove any existing code before making a new one! if {telelink::users::%player%::code} is set: set {_code} to {telelink::users::%player%::code} clear {telelink::codes::%{_code}%} clear {telelink::users::%player%::code} set {_code} to genTGCode() set {telelink::codes::%{_code}%} to player set {telelink::users::%player%::code} to {_code} send message "&7---- {@p} &7----%nl%%nl%&bType the command below in &9&n{@bot_user}&b's chat to link your minecraft account to your telegram account!%nl%%nl%/telelink %{_code}%%nl%&7&oIf you disconnect without linking this code will no longer be valid and you'll have to generate a new one.%nl%&7---- {@p} &7----" else: send message "{@p} &cYour minecraft account is already linked to a telegram account!%nl%&7&oUnlink it with /telelink unlink" else if arg-1 is "unlink": if {telelink::users::%player%::userid} is set: set {_id} to {telelink::users::%player%::userid} clear {telelink::users::%player%::userid} clear {telelink::users::%player%::username} clear {telelink::telegram::%{_id}%} send message "{@p} &bYour minecraft account is no longer linked to your telegram account." send telegram message "Your minecraft account %player% has been unlinked." to {_id} with bot "{@bot_user}" else: send message "{@p} &bYour minecraft account is not linked to any telegram." else if arg-1 is "forceunlink": if player has permission "telelink.admin": if arg-2 is set: if {telelink::users::%arg-2%::userid} is not set: set {_id} to {telelink::users::%arg-2%::userid} clear {telelink::users::%arg-2%::userid} clear {telelink::users::%arg-2%::username} clear {telelink::telegram::%{_id}%} send message "{@p} &bYou have unlinked %arg-2%'s telegram account." else: send message "{@p} &cThis user does not have a linked telegram account." else: send message "{@p} &cSpecify the player to unlink." else: send message "{@p} &cYou don't have the permission &4telelink.admin&c." else if arg-1 is "view" or "profile" or "user": if player has permission "telelink.view": if arg-2 is set: if {telelink::users::%arg-2%::userid} is set: send message "&7--- &b%arg-2%'s &9PROFILE &7---%nl%&9- Username: &b&n%{telelink::users::%arg-2%::username}%%nl%- ID: &b&n%{telelink::users::%arg-2%::userid}%%nl%&7--- {@p} &7---" else: send message "{@p} &c%arg-2% does not have a telegram linked." else: send message "{@p} &cSpecify the username of the player to view." else: send message "{@p} &cYou don't have the permission &4telelink.view&c." else if arg-1 is "2fa": if player has permission "telelink.2fa": do2FA(player) else: send message "{@p} &cYou don't have the permission &4telelink.2fa&c." else if arg-1 is "debug" or "reset": if player has permission "telelink.admin": clear {telelink::*} send message "{@p} &b&oAll skript variables cleared." else: send message "{@p} &cYou don't have the permission &4telelink.admin&c." else: if {telelink::users::%player%::userid} is set: send message "&7--- &b%player%'s &9PROFILE &7---%nl%&9- Username: &b&n%{telelink::users::%player%::username}%%nl%&9- ID: &b&n%{telelink::users::%player%::userid}%%nl%&7--- {@p} &7---" else: send message "{@p} &cYou don't have a telegram profile linked!%nl%&7&oLink one with /telelink link" on quit: set {_code} to {telelink::users::%player%::code} clear {telelink::users::%player%::code} clear {telelink::codes::%{_code}%} clear {telelink::users::%player%::2facode} on join: if {@credits} is true: send message "{@p}&b Plugin by &9DereWah &b[&9&nLINK&b]" if is2FAAuthorized(player) is false: clear {telelink::users::%player%::2fa} function getTelegramID(p: offlineplayer) :: integer: return {telelink::users::%{_p}%::userid} function getTelegramUsername(p: offlineplayer) :: text: return {telelink::users::%{_p}%::username} function getBotUser() :: text: return "{@bot_user}" function is2FAAuthorized(p: offlineplayer) :: boolean: if {telelink::2fa::%{_p}%::2fa} is {_p}'s ip: return true clear {telelink::2fa::%{_p}%::2fa} return false function getLinkedMinecraft(id: text) :: offlineplayer: #Skript can't handle long numbers as integers, so we have to treat them as strings. return {telelink::telegram::%{_id}%} function do2FA(p: player): if getTelegramID({_p}) is set: if is2FAAuthorized({_p}) is false: if {telelink::2fa::%{_p}%::2facode} is not set: set {_code} to a random integer between 1 and 99 set {_b1} to a new inline button with text "%{_code}%" with callback data "telelink2fa:%{_code}%" add {_b1} to {_b::*} add {_code} to {_ints::*} loop 5 times: set {_fake} to a random integer between 1 and 99 while {_ints::*} contains {_fake}: set {_fake} to a random integer between 1 and 99 add {_fake} to {_ints::*} set {_b1} to a new inline button with text "%{_fake}%" with callback data "telelink2fa:%{_fake}%" add {_b1} to {_b::*} set {_b::*} to shuffled {_b::*} set {telelink::2fa::%{_p}%::2facode} to {_code} set {_kb} to a new inline keyboard with buttons {_b::*} set {_mess} to a new telegram message with text "🔒 *2FA REQUESTED* 🔒%nl%%nl%ℹī¸ If you received this message, you requested to *authorize yourself* in {@server_ip}.%nl%%nl%Click on the 🔑 code you received in chat to confirm.%nl%%nl%You didn't request this? Ignore this message." set inline keyboard of {_mess} to {_kb} send telegram message {_mess} with markdown to getTelegramID({_p}) with bot getBotUser() set {_last} to last sent telegram message with bot getBotUser() send message "{@p} &bYou have received a 2FA request on telegram.%nl%{@p} &bTo confirm your identity, click on the code &9&l%{_code}%&b.%nl%&7&oYou have {@2fa_cooldown}." to {_p} wait {@2fa_cooldown} if {telelink::2fa::%{_p}%::2facode} is {_code}: send message "{@p} &bYou didn't 2FA verify in time." to {_p} set {_expired} to a new telegram message with text "❌ 2FA Request Expired ❌" edit telegram message {_last} to {_expired} with bot getBotUser() clear {telelink::2fa::%{_p}%::2facode} else: send message "{@p} &cYou already have another 2fa request active. Please wait or relog." to {_p} else: send message "{@p} &cYou already are 2FA authorized." to {_p} else: send message "{@p} &cYou don't have a linked telegram account.%nl%&7&oLink one with /telelink link" to {_p} on callback query: if "%event-telegram bot%" is getBotUser(): if callback data of event-callback query contains "telelink2fa": set {_mess} to a new telegram message with text "🔐 CHECKING... 🔐" edit telegram message event-telegram message to {_mess} set {_data::*} to callback data of event-callback query split at ":" set {_p} to getLinkedMinecraft("%id of event-telegram user%") if {_p} is set: if {_p} is online: if {_data::2} parsed as integer is {telelink::2fa::%{_p}%::2facode}: clear {telelink::2fa::%{_p}%::2facode} set {telelink::2fa::%{_p}%::2fa} to {_p}'s ip edit telegram message event-telegram message to "✅ Verified. ✅%nl%%nl%Date: %now%" send message "{@p} &bYou authorized with 2FA." to {_p} wait {@2fa_session_length} clear {telelink::2fa::%{_p}%::2fa} else: edit telegram message event-telegram message to "❌ Unable to verify ❌" clear {telelink::2fa::%{_p}%::2fa} clear {telelink::2fa::%{_p}%::2facode} send message "{@p} &cUnable to verify 2FA." to {_p} else: edit telegram message event-telegram message to "❌ The linked user is not online anymore on Minecraft. ❌" clear {telelink::2fa::%{_p}%::2fa} clear {telelink::2fa::%{_p}%::2facode} else: edit telegram message event-telegram message to "❌ This account is not linked anymore. ❌" clear {telelink::2fa::%{_p}%::2fa} clear {telelink::2fa::%{_p}%::2facode}