Advertisement
einstein95

stats.py

Oct 29th, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from __future__ import print_function
  4. import re
  5. import urllib.request
  6. import xchat
  7.  
  8. __module_name__ = "altwfc stats"
  9. __module_version__ = "0.01a"
  10. __module_description__ = "Checks the stats page for a gamecode [/stat]"
  11.  
  12. print("\0034", __module_name__, __module_version__, "(/stat) loading...\003")
  13.  
  14. def delayed_say(text, context):
  15.     def on_timer(userdata):
  16.         context.command("SAY " + text)
  17.         return 0
  18.  
  19.     xchat.hook_timer(1, on_timer)
  20.  
  21. def stat(word, word_eol, userdata):
  22.     if re.search('(?:^!stat$|^!s$)', word[1], re.IGNORECASE):
  23.         source = urllib.request.urlopen("http://104.131.93.87:9001").read().decode('utf-8')
  24.         games = re.findall("<tr>\n +<td>(.+?)</td>\n +<td><center>(\d+)</center>", source)
  25.         if len(games) == 0:
  26.             s = 'No-one online.'
  27.             delayed_say(s, xchat.get_context())
  28.         else:
  29.             s = ''
  30.             for i in games:
  31.                 s += '{:}: {:}; '.format(*i)
  32.             delayed_say(s[:-2], xchat.get_context())
  33.  
  34.  
  35. xchat.hook_print("Channel Message", stat)
  36. xchat.hook_print("Your Message", stat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement