1
1
from redbot .core import commands , checks
2
2
from .ase import MTAServerlist
3
3
4
- import discord , aiohttp , asyncio , time
4
+ import discord , aiohttp , asyncio , time , re
5
5
6
6
class Stats (commands .Cog ):
7
7
"""My custom cog"""
@@ -46,3 +46,31 @@ async def top(self, ctx):
46
46
if not v ["version" ].endswith ("n" ):
47
47
embed .add_field (name = "**" + v ["name" ]+ "**" , value = str (v ["players" ])+ "/" + str (v ["maxplayers" ]), inline = False )
48
48
await ctx .channel .send (embed = embed )
49
+
50
+ @stats .command ()
51
+ @commands .cooldown (1 , 30 , commands .BucketType .user )
52
+ @commands .guild_only ()
53
+ async def server (self , ctx , host ):
54
+ """Shows the provided server stats."""
55
+ async with ctx .typing ():
56
+ host_ip = re .findall (r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" , host )
57
+ host_port = re .findall (r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:(\d+)" , host )
58
+ if not host_ip :
59
+ embed = discord .Embed (colour = discord .Colour (0xf5a623 ), description = "**Invalid ip address.**" )
60
+ return await ctx .channel .send (embed = embed )
61
+ else :
62
+ host_ip = host_ip [0 ]
63
+ if not host_port :
64
+ host_port = "22003"
65
+ else :
66
+ host_port = host_port [0 ]
67
+ async with aiohttp .ClientSession () as session :
68
+ async with session .get (self .url ) as response :
69
+ ase = MTAServerlist ()
70
+ await ase .parse (await response .read ())
71
+ for v in ase .servers :
72
+ if str (v ["ip" ]) == str (host_ip ) and str (v ["port" ]) == str (host_port ):
73
+ embed = discord .Embed (colour = discord .Colour (0xf5a623 ), description = "**" + v ["name" ]+ "**\n " + str (v ["players" ])+ "/" + str (v ["maxplayers" ]))
74
+ return await ctx .channel .send (embed = embed )
75
+ embed = discord .Embed (colour = discord .Colour (0xf5a623 ), description = "**No result.**" )
76
+ return await ctx .channel .send (embed = embed )
0 commit comments