@flint oar
cattosarus Uploaded Some Code
Hello. I'm a python beginner working on a twitch bot, would like to get some code review from someone who is good at python. I want to keep my code clean, readable and corrent, of course 🙂
This project works fine, hovewer, i have used some new things to me, like dataclasses.
Please tell me which moments can I improve and in which way they should be improved by your opinionCould upload project as an archive, but probably some people gonna blame me, so just files. Its not big anyways.
Thanks in advance!
- Windows 10
- Python 3.9
- No
- Currently no
- Twitch bot
Attachment: requirements.txt
irc==20.1.0
ossapi[async]==3.1.9
twitchio==2.6.0
Attachment: run.py
import logging
from osu_requests.twitch_bot import TwitchBot
LOG_FILENAME = "osu_requests.log"
LOG_FORMAT = "%(asctime)s | %(levelname)s | %(message)s"
LOG_DATE_FORMAT = "%d.%m.%Y %H:%M:%S"
logging.basicConfig(
format=LOG_FORMAT,
datefmt=LOG_DATE_FORMAT,
level=logging.INFO,
handlers = [
logging.StreamHandler(),
logging.FileHandler(LOG_FILENAME, encoding="utf-8")
]
)
if __name__ == '__main__':
bot = TwitchBot()
bot.run()
Attachment: irc\_bot.py
import asyncio
import logging
from irc.bot import SingleServerIRCBot, ExponentialBackoff
from irc.client import ServerConnection, Event
class IrcBot(SingleServerIRCBot):
def __init__(self, username, server, port=6667, password=None):
recon = ExponentialBackoff(min_interval=5, max_interval=30)
SingleServerIRCBot.__init__(self, [(server, port, password)], username, username, recon=recon)
self.messages_queue = asyncio.Queue()
def on_welcome(self, c: ServerConnection, e: Event):
logging.info(f"Connected to osu!IRC server as {self._nickname}")
def send_message(self, target: str, text: str):
target = target.replace(" ", "_")
self.connection.privmsg(target, text)
logging.info(f"In-Game message was successfully sent to {target}")
Uploaded these files to a Gist
For safety reasons we do not allow file attachments.