-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitchbot.py
64 lines (47 loc) · 1.94 KB
/
twitchbot.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import datetime
from aiohttp import request
import twitchio
from twitchio.ext import commands
import requests
from discord import Webhook, RequestsWebhookAdapter
import os
import dotenv
import json
with open("config.json") as config_file:
config = json.load(config_file)
dotenv.load_dotenv()
class Bot(commands.Bot):
def __init__(self):
super().__init__(
irc_token=os.environ.get("TwitchTOKEN"),
client_id=os.environ.get("client_id"),
nick=config["nickname"],
prefix=config["prefix"],
initial_channels=config["channels"],
)
async def event_ready(self):
print(f"Twitch Bot Ready | {self.nick}")
async def event_message(self, message):
print(
f"[MESSAGE LOGS] ({message.channel.name}) "
+ message.author.name
+ " - "
+ message.content
)
if message.author.name != "doobme":
webhook = Webhook.from_url(os.environ.get("webhook_url"), adapter=RequestsWebhookAdapter())
webhook.send(message.author.name + " - " + message.content + f"\nChannel: `{message.channel.name}`")
print("Sent: " + message.content + "\nTo Discord.")
await self.handle_commands(message)
for channel in self.initial_channels:
if message.author.name != "doobme":
if message.channel.name != channel:
xd = self.get_channel(channel)
await xd.send(f"[Channel: {message.channel.name}] {message.author.name} - {message.content}")
@commands.command(name="ping", aliases=["ding"])
async def test_command(self, ctx):
await ctx.send(f"FeelsDankMan 🔔 ding @{ctx.author.name}")
async def discord_relay_thing_command(self, msg, username):
for channel in self.initial_channels:
xd = self.get_channel(channel)
await xd.send(f"[Discord] {username} - {msg}")