commit a4bb76be270e7eb7e002fcd34abd159b3dcfa013 Author: Hipstercat Date: Mon Aug 31 19:58:01 2020 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a81c8ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,138 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ diff --git a/cogs/wynncraft/__init__.py b/cogs/wynncraft/__init__.py new file mode 100644 index 0000000..181f587 --- /dev/null +++ b/cogs/wynncraft/__init__.py @@ -0,0 +1,9 @@ +from .wynncraft import WynncraftCog +import asyncio + + +def setup(bot): + n = WynncraftCog(bot) + loop = asyncio.get_event_loop() + loop.create_task(n.loop()) + bot.add_cog(n) \ No newline at end of file diff --git a/cogs/wynncraft/wynncraftcog.py b/cogs/wynncraft/wynncraftcog.py new file mode 100644 index 0000000..6f854f8 --- /dev/null +++ b/cogs/wynncraft/wynncraftcog.py @@ -0,0 +1,81 @@ +import asyncio +from redbot.core import commands +from redbot.core import Config, checks +from discord import TextChannel +import traceback +import requests + + +class WynncraftCog(commands.Cog): + def __init__(self): + self.config = Config.get_conf(self, identifier=48775419874) + default_guild = { + "tracked": [], + "channel": None + } + self.config.register_guild(**default_guild) + + @commands.command() + @checks.admin_or_permissions(manage_guild=True) + async def track(self, ctx, username: str): + tracked = await self.config.guild(ctx.guild).tracked() + if username in tracked: + await ctx.send(":x: **%s** est déjà tracké" % username) + else: + tracked.append(username) + await self.config.guild(ctx.guild).tracked.set(tracked) + await ctx.send(":white_check_mark: **%s** est désormais tracké" % username) + + @commands.command() + @checks.admin_or_permissions(manage_guild=True) + async def untrack(self, ctx, username: str): + tracked = await self.config.guild(ctx.guild).tracked() + if username in tracked: + tracked.remove(username) + await self.config.guild(ctx.guild).tracked.set(tracked) + await ctx.send(":white_check_mark: **%s** ne sera plus tracké" % username) + else: + await ctx.send(":x: **%s** n'était pas tracké" % username) + + @commands.command() + @checks.admin_or_permissions(manage_guild=True) + async def tracked(self, ctx): + tracked = await self.config.guild(ctx.guild).tracked() + await ctx.send("Les joueurs trackés sont: %s" % ",".join(tracked)) + + @commands.command() + @checks.admin_or_permissions(manage_guild=True) + async def set_channel(self, ctx, channel: TextChannel): + i = channel.id + await self.config.guild(ctx.guild).channel.set(i) + await ctx.send("Les messages seront désormais envoyés dans %s" % channel.mention) + + async def loop(self): + await self.bot.wait_until_ready() + last_status = {} + while self is self.bot.get_cog("WynncraftCog"): + async for guild in self.bot.fetch_guilds(limit=150): + guild_id = guild.id + try: + channel_id = await self.config.guild(guild).channel() + if channel_id: + for tracked in await self.config.guild(guild).tracked(): + r = requests.get("https://api.wynncraft.com/v2/player/%s/stats" % tracked).json() + for cl in r["data"][0]["classes"]: + if guild_id not in last_status: + last_status[guild_id] = {} + + if tracked not in last_status[guild_id]: + last_status[guild_id][tracked] = {} + + if cl["name"] not in last_status[guild_id][tracked]: + last_status[guild_id][tracked][cl["name"]] = cl + + if cl["professions"]["combat"]["level"] > last_status[guild_id][tracked][cl["name"]]["professions"]["combat"]["level"]: + channel = self.bot.get_channel(channel_id) + await channel.send(":high_brightness: %s a level up au niveau %s! GG!" % (tracked, cl["professions"]["combat"]["level"])) + + last_status[guild_id][tracked][cl["name"]] = cl + except: + traceback.print_exc() + await asyncio.sleep(30) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d3362d6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Red-DiscordBot +requests \ No newline at end of file