-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirc.py
47 lines (32 loc) · 1.11 KB
/
irc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import JustIRC
import requests
import config
token = config.BOT_TOKEN_FRAGOLONE
# chat_id = config.ID_DIOCHAN
chat_id = config.ID_TESTING
ircbot = JustIRC.IRCConnection()
def send_tg_message(sender: str, message: str, chat_id=chat_id):
TELEGRAM_URL = "https://api.telegram.org/ircbot"
ircbot_TOKEN = config.ircbot_TOKEN
# < with <, > with > and & with &
message = f"<{sender}> {message}"
message = message.replace("<", "<").replace(">", ">").replace("&", "&")
data = {
"chat_id": chat_id,
"text": message,
"parse_mode": "HTML",
}
requests.post(f"{TELEGRAM_URL}{ircbot_TOKEN}/sendMessage", data=data)
def on_connect(ircbot):
ircbot.set_nick("EmiliaParanoica")
ircbot.send_user_packet("EmiliaParanoica")
def on_welcome(ircbot):
ircbot.join_channel("#diochan")
def on_message(ircbot, channel, sender, message):
send_tg_message(sender, message)
ircbot.on_connect.append(on_connect)
ircbot.on_welcome.append(on_welcome)
ircbot.on_public_message.append(on_message)
# ircbot.on_packet
ircbot.connect("irc.rizon.org")
ircbot.run_loop()