added support for non top200 permanent games

This commit is contained in:
Giovanni Harting 2019-07-19 10:17:20 +02:00
parent 12c02eed22
commit 4e4b3889d4
3 changed files with 49 additions and 29 deletions

View File

@ -6,6 +6,7 @@ from threading import Timer
import requests
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
@ -43,14 +44,7 @@ class autochannel(MumoModule):
else:
self.top_list = None
# Load wordlist
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
self.glist = SteamApps.get_instance()
Timer(60 * 60, self.update_timer).start()
@ -101,10 +95,7 @@ class autochannel(MumoModule):
self.add_random_channel(server)
def add_random_channel(self, server):
word = self.wordlist[random.randint(0, len(self.wordlist))]
while not word.isalnum():
word = self.wordlist[random.randint(0, len(self.wordlist))]
word = chr(945 + random.randint(0, 24))
self.log().info("Added new channel " + word)
server.addChannel(word, self.random_root.id)
@ -124,10 +115,15 @@ class autochannel(MumoModule):
for pgame in self.game_channel_permanent:
if pgame:
game = self.top_list[str(pgame)]
if str(pgame) in self.top_list:
game = self.top_list[str(pgame)]
if game:
games[game["name"]] = game
if 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)
games_matched = []

View File

@ -11,6 +11,7 @@ from bs4 import BeautifulSoup
from mumo_module import (commaSeperatedIntegers,
MumoModule)
from tools.SteamApps import SteamApps
# 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}"
@ -57,14 +58,7 @@ class chatparser(MumoModule):
self.amazon_api = AmazonAPI(self.amazon_access_key, self.amazon_secret_key,
self.amazon_assoc_tag, region=self.amazon_region)
# 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()
self.log().info("Got {} apps from steam".format(len(self.glist["applist"]["apps"])))
else:
self.glist = None
self.glist = SteamApps.get_instance()
def connected(self):
manager = self.manager()
@ -152,12 +146,10 @@ class chatparser(MumoModule):
genre = "Unkown Genre"
if self.glist:
for game in self.glist["applist"]["apps"]:
if appid == game["appid"]:
self.sendMessage(server, user, message,
'<a href="http://store.steampowered.com/app/{0}">{1}</a> | {2} | {3}'.format(
appid, game["name"], genre, price))
return
game = self.glist.appid2game(appid)
self.sendMessage(server, user, message,
'<a href="http://store.steampowered.com/app/{0}">{1}</a> | {2} | {3}'.format(
appid, game["name"], genre, price))
def parse_amazon(self, item_id, user, server, message):
self.log().info("AMAZON: %s", item_id)

32
tools/SteamApps.py Normal file
View 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