July 15, 2022 at 9:48 AM
I've just made a really simple shoutbox to discord forward bot a couple days ago and wanna share it.
Dependencies
It's written in python, you'll need these two packages:
Installation
1. Get your shoutbox token by opening bf homepage, open dev tool, head to the console and enter "token" to get your token, then replace SB_TOKEN in the code.
2. Get your discord webhook url, google it if you don't know how, replace the WEBHOOK in the code.
Python Code
This is just a really simple python script, modify it as you want.
Pom told me that he wouldn't mind me making this bot, but if this violates any rules please take this thread down <3
Dependencies
It's written in python, you'll need these two packages:
pip install python-socketio[asyncio_client]
pip install discord-webhook
Installation
1. Get your shoutbox token by opening bf homepage, open dev tool, head to the console and enter "token" to get your token, then replace SB_TOKEN in the code.
2. Get your discord webhook url, google it if you don't know how, replace the WEBHOOK in the code.
Python Code
import asyncio
import socketio
import typing as t
from discord_webhook import DiscordWebhook
# the sb socket token, open bf homepage, go to the console and enter "token" to get it
SB_TOKEN = "YOUR_TOKEN_HERE"
# discord webhook url
WEBHOOK = "YOUR_WEBHOOK_HERE"
# Rank prefi
PREFIX_NOOB = "\U0001F4A9 "
PREFIX_VIP = "\U0001F539 "
PREFIX_MVP = "\U0001F48E "
PREFIX_GOD = "\U0001F451 "
PREFIX_MOD = "\U000026D4 [MOD] "
PREFIX_ADMIN = "\U0001F4DB [ADMIN] "
PREFIX_OWNER = "\U0001F496 [OWNER] "
class BFRank(object):
Noob = 0
VIP = 1
MVP = 2
GOD = 3
MOD = 4
ADMIN = 5
OWNER = 6
class BFUser(object):
def __init__(self, user: t.Dict[str, t.Any]) -> None:
self.uid = user["uid"]
self.gid = user["gid"]
self.username = user["username"]
self.styled_name = user["StyledName"]
self.discord_username = self.username
self.rank = BFRank.Noob
self._get_rank()
# a retarded way to get user rank
def _get_rank(self) -> None:
rank_checks: t.Dict[str, t.Dict[str, t.Union[BFRank, str]]] = {
'class="rf_noob"': {"rank": BFRank.Noob, "prefix": PREFIX_NOOB},
'class="rf_i rf_vip"': {"rank": BFRank.VIP, "prefix": PREFIX_VIP},
'class="rf_i rf_mvp"': {"rank": BFRank.MVP, "prefix": PREFIX_MVP},
'class="rf_i rf_god"': {"rank": BFRank.GOD, "prefix": PREFIX_GOD},
'class="rf_mod"': {"rank": BFRank.MOD, "prefix": PREFIX_MOD},
'class="rf_a"': {"rank": BFRank.ADMIN, "prefix": PREFIX_ADMIN},
'class="rf_o"': {"rank": BFRank.OWNER, "prefix": PREFIX_OWNER},
}
for style, value in rank_checks.items():
if style in self.styled_name:
self.discord_username = f"{value['prefix']}{self.username}"
self.rank = value["rank"]
break
class SBMessage(object):
def __init__(self, message: t.Dict[str, t.Any]) -> None:
self.user = BFUser(message["user"])
self.id = message["id"]
self.html = message["text"]
self.type = message["type"]
self.text = self.html
# update the plain text
def update(self, text: str) -> None:
self.text = text
class BFShoutBoxBot(object):
def __init__(self, token: str, webhook: str) -> None:
self.token = token
self.webhook = webhook
self.messages: t.List[SBMessage] = []
self.sio = socketio.AsyncClient()
@self.sio.event
async def connect():
print("Bot connected")
@self.sio.event
async def disconnect():
print("Bot disconnected")
@self.sio.on("users")
async def on_users(data):
# online list
pass
@self.sio.on("history")
async def on_history(data):
# message history on first connect
pass
@self.sio.on("message-receive")
async def on_message_receive(message):
if message["type"] == "shout":
msg = SBMessage(message)
self.messages.append(msg)
# emit message-get to get the plain text message
await self.sio.emit("message-get", {"id": msg.id})
# server will reponse a message-give on message-get
@self.sio.on("message-give")
async def on_message_receive(message):
if len(self.messages) == 0:
return
last_msg = self.messages[-1]
last_msg.update(message["text"])
self.WebhookSend(last_msg)
def WebhookSend(self, msg: SBMessage):
def escape_markdown(text: str) -> str:
return (
text.replace("*", "\\*")
.replace("_", "\\_")
.replace("~", "\\~")
.replace(">", "\\>")
.replace("`", "\\`")
)
def GetBFAvatar(uid: str):
# the extension could be .gif, .jpg, .jpeg,... or the user doesn't have avatar
# but there is no way to know it without fetching their entire profile
extension = "png" # change this to jpg or something else if you want
return f"https://external-content.duckduckgo.com/iu/?u=https://breached.to/uploads/avatars/avatar_{msg.user.uid}.{extension}"
DiscordWebhook(
url=WEBHOOK,
rate_limit_retry=True,
content=escape_markdown(msg.text),
username=msg.user.discord_username,
avatar_url=GetBFAvatar(msg.user.uid),
).execute()
async def start(self):
await self.sio.connect(
f"https://zoom-new.breached.to/socket.io/?token={self.token}",
headers={
"User-Agent": "ShoutBox Bot",
},
)
await self.sio.wait()
bot = BFShoutBoxBot(SB_TOKEN, WEBHOOK)
asyncio.run(bot.start())
This is just a really simple python script, modify it as you want.
Pom told me that he wouldn't mind me making this bot, but if this violates any rules please take this thread down <3


