added support for non top200 permanent games
This commit is contained in:
@@ -6,6 +6,7 @@ from threading import Timer
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from mumo_module import (commaSeperatedIntegers, MumoModule)
|
from mumo_module import (commaSeperatedIntegers, MumoModule)
|
||||||
|
from tools.SteamApps import SteamApps
|
||||||
from tools.Utils import find_create_channel, get_empty_channels, get_subchannels, get_user_for_channel
|
from tools.Utils import find_create_channel, get_empty_channels, get_subchannels, get_user_for_channel
|
||||||
|
|
||||||
|
|
||||||
@@ -43,14 +44,7 @@ class autochannel(MumoModule):
|
|||||||
else:
|
else:
|
||||||
self.top_list = None
|
self.top_list = None
|
||||||
|
|
||||||
# Load wordlist
|
self.glist = SteamApps.get_instance()
|
||||||
r = requests.get("https://raw.githubusercontent.com/dwyl/english-words/master/words.txt")
|
|
||||||
|
|
||||||
if r.status_code == 200:
|
|
||||||
self.wordlist = r.text.splitlines()
|
|
||||||
self.log().info("Loaded {} words".format(len(self.wordlist)))
|
|
||||||
else:
|
|
||||||
self.wordlist = None
|
|
||||||
|
|
||||||
Timer(60 * 60, self.update_timer).start()
|
Timer(60 * 60, self.update_timer).start()
|
||||||
|
|
||||||
@@ -101,10 +95,7 @@ class autochannel(MumoModule):
|
|||||||
self.add_random_channel(server)
|
self.add_random_channel(server)
|
||||||
|
|
||||||
def add_random_channel(self, server):
|
def add_random_channel(self, server):
|
||||||
word = self.wordlist[random.randint(0, len(self.wordlist))]
|
word = chr(945 + random.randint(0, 24))
|
||||||
|
|
||||||
while not word.isalnum():
|
|
||||||
word = self.wordlist[random.randint(0, len(self.wordlist))]
|
|
||||||
|
|
||||||
self.log().info("Added new channel " + word)
|
self.log().info("Added new channel " + word)
|
||||||
server.addChannel(word, self.random_root.id)
|
server.addChannel(word, self.random_root.id)
|
||||||
@@ -124,10 +115,15 @@ class autochannel(MumoModule):
|
|||||||
|
|
||||||
for pgame in self.game_channel_permanent:
|
for pgame in self.game_channel_permanent:
|
||||||
if pgame:
|
if pgame:
|
||||||
game = self.top_list[str(pgame)]
|
if str(pgame) in self.top_list:
|
||||||
|
game = self.top_list[str(pgame)]
|
||||||
|
|
||||||
if game:
|
if game:
|
||||||
games[game["name"]] = game
|
games[game["name"]] = game
|
||||||
|
else:
|
||||||
|
game = self.glist.appid2game(pgame)
|
||||||
|
if game:
|
||||||
|
games[game["name"]] = game
|
||||||
|
|
||||||
channels = get_subchannels(server, self.game_root.id)
|
channels = get_subchannels(server, self.game_root.id)
|
||||||
games_matched = []
|
games_matched = []
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from bs4 import BeautifulSoup
|
|||||||
|
|
||||||
from mumo_module import (commaSeperatedIntegers,
|
from mumo_module import (commaSeperatedIntegers,
|
||||||
MumoModule)
|
MumoModule)
|
||||||
|
from tools.SteamApps import SteamApps
|
||||||
|
|
||||||
# YT
|
# YT
|
||||||
youtube_api_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails%2Csnippet%2Cstatistics&id={0}&fields=items(contentDetails(definition%2Cduration)%2Clocalizations%2Csnippet%2Ftitle%2Cstatistics)%2CpageInfo%2FtotalResults&key={1}"
|
youtube_api_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails%2Csnippet%2Cstatistics&id={0}&fields=items(contentDetails(definition%2Cduration)%2Clocalizations%2Csnippet%2Ftitle%2Cstatistics)%2CpageInfo%2FtotalResults&key={1}"
|
||||||
@@ -57,14 +58,7 @@ class chatparser(MumoModule):
|
|||||||
self.amazon_api = AmazonAPI(self.amazon_access_key, self.amazon_secret_key,
|
self.amazon_api = AmazonAPI(self.amazon_access_key, self.amazon_secret_key,
|
||||||
self.amazon_assoc_tag, region=self.amazon_region)
|
self.amazon_assoc_tag, region=self.amazon_region)
|
||||||
|
|
||||||
# Load steam appid <-> game list
|
self.glist = SteamApps.get_instance()
|
||||||
r = requests.get("http://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json")
|
|
||||||
|
|
||||||
if r.status_code == 200:
|
|
||||||
self.glist = r.json()
|
|
||||||
self.log().info("Got {} apps from steam".format(len(self.glist["applist"]["apps"])))
|
|
||||||
else:
|
|
||||||
self.glist = None
|
|
||||||
|
|
||||||
def connected(self):
|
def connected(self):
|
||||||
manager = self.manager()
|
manager = self.manager()
|
||||||
@@ -152,12 +146,10 @@ class chatparser(MumoModule):
|
|||||||
genre = "Unkown Genre"
|
genre = "Unkown Genre"
|
||||||
|
|
||||||
if self.glist:
|
if self.glist:
|
||||||
for game in self.glist["applist"]["apps"]:
|
game = self.glist.appid2game(appid)
|
||||||
if appid == game["appid"]:
|
self.sendMessage(server, user, message,
|
||||||
self.sendMessage(server, user, message,
|
'<a href="http://store.steampowered.com/app/{0}">{1}</a> | {2} | {3}'.format(
|
||||||
'<a href="http://store.steampowered.com/app/{0}">{1}</a> | {2} | {3}'.format(
|
appid, game["name"], genre, price))
|
||||||
appid, game["name"], genre, price))
|
|
||||||
return
|
|
||||||
|
|
||||||
def parse_amazon(self, item_id, user, server, message):
|
def parse_amazon(self, item_id, user, server, message):
|
||||||
self.log().info("AMAZON: %s", item_id)
|
self.log().info("AMAZON: %s", item_id)
|
||||||
|
|||||||
32
tools/SteamApps.py
Normal file
32
tools/SteamApps.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class SteamApps:
|
||||||
|
__instance = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_instance():
|
||||||
|
""" Static access method. """
|
||||||
|
if not SteamApps.__instance:
|
||||||
|
SteamApps()
|
||||||
|
return SteamApps.__instance
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
""" Virtually private constructor. """
|
||||||
|
if SteamApps.__instance:
|
||||||
|
raise Exception("This class is a singleton!")
|
||||||
|
else:
|
||||||
|
SteamApps.__instance = self
|
||||||
|
|
||||||
|
# Load steam appid <-> game list
|
||||||
|
r = requests.get("http://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json")
|
||||||
|
|
||||||
|
if r.status_code == 200:
|
||||||
|
self.glist = r.json()
|
||||||
|
else:
|
||||||
|
self.glist = None
|
||||||
|
|
||||||
|
def appid2game(self, appid):
|
||||||
|
for game in self.glist["applist"]["apps"]:
|
||||||
|
if appid == game["appid"]:
|
||||||
|
return game
|
||||||
Reference in New Issue
Block a user