-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (51 loc) · 1.83 KB
/
main.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
64
import os
from dotenv import load_dotenv
from twitchio.ext import commands
from pynput.keyboard import Key, Controller
import time
# Charger les variables d'environnement depuis le fichier .env
load_dotenv()
# Récupérer les informations sensibles depuis les variables d'environnement
TWITCH_TOKEN = os.getenv('TWITCH_TOKEN')
TWITCH_NICKNAME = os.getenv('TWITCH_NICKNAME')
TWITCH_CHANNEL = os.getenv('TWITCH_CHANNEL')
# Bot Twitch
class Bot(commands.Bot):
def __init__(self):
super().__init__(token=TWITCH_TOKEN, prefix='!', initial_channels=[TWITCH_CHANNEL])
async def event_ready(self):
print(f'Bot is ready and logged in as | {self.nick}')
async def event_message(self, message):
if message.author.name.lower() == self.nick.lower():
return
print(f'{message.author.name}: {message.content}')
await self.handle_commands(message)
handle_pokemon_command(message.content)
# Fonction pour traiter les commandes du chat
def handle_pokemon_command(command):
valid_commands = ["up", "down", "left", "right", "a", "b", "y", "x", "l", "r", "start", "select"]
if command.lower() in valid_commands:
inject_command_into_game(command.lower())
keyboard = Controller()
def inject_command_into_game(command):
key_mapping = {
"up": Key.up,
"down": Key.down,
"left": Key.left,
"right": Key.right,
"a": 'a', # Assurez-vous que cela correspond aux touches de votre émulateur
"b": 'b',
"y": 'y',
"x": 'x',
"l": 'l',
"r": 'r',
"start": Key.enter,
"select": Key.backspace
}
if command in key_mapping:
key = key_mapping[command]
keyboard.press(key)
time.sleep(0.2) # Pour s'assurer que la touche est enregistrée
keyboard.release(key)
bot = Bot()
bot.run()