def load_text() -> cj.ClassyDict: text = {} for filename in os.listdir("data/text"): with open(f"data/text/{filename}", "r", encoding="utf8") as f: text.update(cj.loads(f.read())) return cj.ClassyDict(text)
async def mcstatus(self, ctx, host=None, port: int = None): """Checks the status of a given Minecraft server""" if host is None: if ctx.guild is None: raise commands.MissingRequiredArgument(cj.ClassyDict({'name': 'host'})) combined = (await self.db.fetch_guild(ctx.guild.id))['mcserver'] if combined is None: await self.bot.send(ctx, ctx.l.minecraft.mcping.shortcut_error.format(ctx.prefix)) return else: port_str = '' if port is not None and port != 0: port_str = f':{port}' combined = f'{host}{port_str}' with ctx.typing(): async with self.ses.get(f'https://api.iapetus11.me/mc/status/{combined}', headers={'Authorization': self.k.vb_api}) as res: # fetch status from api jj = await res.json() if not jj['success'] or not jj['online']: embed = discord.Embed(color=self.d.cc, title=ctx.l.minecraft.mcping.title_offline.format(self.d.emojis.offline, combined)) await ctx.send(embed=embed) return player_list = jj.get('players_names', []) if player_list is None: player_list = [] players_online = jj['players_online'] # int@ embed = discord.Embed(color=self.d.cc, title=ctx.l.minecraft.mcping.title_online.format(self.d.emojis.online, combined)) embed.add_field(name=ctx.l.minecraft.mcping.latency, value=jj['latency']) ver = jj['version'].get('brand', 'Unknown') embed.add_field(name=ctx.l.minecraft.mcping.version, value=('Unknown' if ver is None else ver)) player_list_cut = [] for p in player_list: if not ('§' in p or len(p) > 16 or len(p) < 3 or ' ' in p or '-' in p): player_list_cut.append(p) player_list_cut = player_list_cut[:24] if len(player_list_cut) < 1: embed.add_field( name=ctx.l.minecraft.mcping.field_online_players.name.format(players_online, jj['players_max']), value=ctx.l.minecraft.mcping.field_online_players.value, inline=False ) else: extra = '' if len(player_list_cut) < players_online: extra = ctx.l.minecraft.mcping.and_other_players.format(players_online - len(player_list_cut)) embed.add_field( name=ctx.l.minecraft.mcping.field_online_players.name.format(players_online, jj['players_max']), value='`' + '`, `'.join(player_list_cut) + '`' + extra, inline=False ) embed.set_image(url=f'https://api.iapetus11.me/mc/statuscard/{combined}?v={random.random()*100000}') if jj['favicon'] is not None: embed.set_thumbnail(url=f'https://api.iapetus11.me/mc/favicon/{combined}') await ctx.send(embed=embed)
async def random_mc_server(self, ctx): """Checks the status of a random Minecraft server""" res = await self.aiohttp.get(f"https://api.minecraft.global/server/random") data = await res.json() if not data["success"]: await asyncio.sleep(1) res = await self.aiohttp.get(f"https://api.minecraft.global/server/random") data = await res.json() server = cj.ClassyDict((await res.json())["payload"]) server_id = server.server_id if server.port: address = server.host + ":" + str(server.port) else: address = server.host async with ctx.typing(): async with self.aiohttp.get( f"https://api.iapetus11.me/mc/status/{address}", headers={"Authorization": self.k.villager_api} ) as res: # fetch status from api jj = await res.json() if not jj["success"] or not jj["online"]: await self.random_mc_server(ctx) return player_list = jj.get("players", ()) if player_list is None: player_list = () else: player_list = [p["name"] for p in player_list] players_online = jj["players_online"] embed = discord.Embed(color=self.d.cc, title=ctx.l.minecraft.mcping.title_plain.format(self.d.emojis.online, address)) embed.description = ctx.l.minecraft.mcping.learn_more.format( f"https://minecraft.global/server/{server_id}?utm_source=villager+bot&utm_medium=discord&utm_id=1" ) embed.set_footer(text=ctx.l.minecraft.mcping.powered_by, icon_url="https://i.ibb.co/SdZHQ4b/full-1.png") embed.add_field(name=ctx.l.minecraft.mcping.latency, value=jj["latency"]) ver = jj["version"].get("brand", "Unknown") embed.add_field(name=ctx.l.minecraft.mcping.version, value=("Unknown" if ver is None else ver)) player_list_cut = [] for p in player_list: if not ("§" in p or len(p) > 16 or len(p) < 3 or " " in p or "-" in p): player_list_cut.append(p) player_list_cut = player_list_cut[:24] if len(player_list_cut) < 1: embed.add_field( name=ctx.l.minecraft.mcping.field_online_players.name.format(players_online, jj["players_max"]), value=ctx.l.minecraft.mcping.field_online_players.value, inline=False, ) else: extra = "" if len(player_list_cut) < players_online: extra = ctx.l.minecraft.mcping.and_other_players.format(players_online - len(player_list_cut)) embed.add_field( name=ctx.l.minecraft.mcping.field_online_players.name.format(players_online, jj["players_max"]), value="`" + "`, `".join(player_list_cut) + "`" + extra, inline=False, ) embed.set_image(url=f"https://api.iapetus11.me/mc/servercard/{address}?v={random.random()*100000}") if jj["favicon"] is not None: embed.set_thumbnail(url=f"https://api.iapetus11.me/mc/favicon/{address}") await ctx.reply(embed=embed, mention_author=False)
async def mcstatus(self, ctx, host=None, port: int = None): """Checks the status of a given Minecraft server""" if host is None: if ctx.guild is None: raise commands.MissingRequiredArgument(cj.ClassyDict({"name": "host"})) combined = (await self.db.fetch_guild(ctx.guild.id))["mc_server"] if combined is None: await self.bot.reply_embed(ctx, ctx.l.minecraft.mcping.shortcut_error.format(ctx.prefix)) return else: port_str = "" if port is not None and port != 0: port_str = f":{port}" combined = f"{host}{port_str}" async with ctx.typing(): async with self.aiohttp.get( f"https://api.iapetus11.me/mc/status/{combined.replace('/', '%2F')}", headers={"Authorization": self.k.villager_api}, ) as res: # fetch status from api jj = await res.json() if not (jj["success"] and jj["online"]): await ctx.reply( embed=discord.Embed( color=self.d.cc, title=ctx.l.minecraft.mcping.title_offline.format(self.d.emojis.offline, combined) ), mention_author=False, ) return player_list = jj.get("players", []) if player_list is None: player_list = () else: player_list = [p["name"] for p in player_list] players_online = jj["players_online"] embed = discord.Embed( color=self.d.cc, title=ctx.l.minecraft.mcping.title_online.format(self.d.emojis.online, combined) ) embed.add_field(name=ctx.l.minecraft.mcping.latency, value=jj["latency"]) ver = jj["version"].get("brand", "Unknown") embed.add_field(name=ctx.l.minecraft.mcping.version, value=("Unknown" if ver is None else ver)) player_list_cut = [] for p in player_list: if not ("§" in p or len(p) > 16 or len(p) < 3 or " " in p or "-" in p): player_list_cut.append(p) player_list_cut = player_list_cut[:24] if len(player_list_cut) < 1: embed.add_field( name=ctx.l.minecraft.mcping.field_online_players.name.format(players_online, jj["players_max"]), value=ctx.l.minecraft.mcping.field_online_players.value, inline=False, ) else: extra = "" if len(player_list_cut) < players_online: extra = ctx.l.minecraft.mcping.and_other_players.format(players_online - len(player_list_cut)) embed.add_field( name=ctx.l.minecraft.mcping.field_online_players.name.format(players_online, jj["players_max"]), value="`" + "`, `".join(player_list_cut) + "`" + extra, inline=False, ) embed.set_image(url=f"https://api.iapetus11.me/mc/servercard/{combined}?v={random.random()*100000}") if jj["favicon"] is not None: embed.set_thumbnail(url=f"https://api.iapetus11.me/mc/favicon/{combined}") await ctx.reply(embed=embed, mention_author=False)
# (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. import classyjson import importlib import os from pymine.types.abc import AbstractParser parsers = classyjson.ClassyDict() for root, dirs, files in os.walk(os.path.join("pymine", "logic", "parsers")): for file in filter((lambda f: f.endswith(".py") and "__" not in f), files): module = importlib.import_module( os.path.join(root, file)[:-3].replace("\\", "/").replace("/", ".")) for name, obj in module.__dict__.items(): try: if issubclass(obj, AbstractParser): parsers[name] = obj except (TypeError, KeyError): # can't call issubclass() on non-classes pass