def update_index(references=REFS): global edited, index refs = CLIENT.loadJson (REFS) for i in list(refs.keys ()): transcript = str () title = str () alt = str () complete_str = str () #FIXME: I really need to fix these magic numbers if refs[i]['stat_com']['status'] == 0: edited = True # Retrieve the comic info from the references title = refs[i]['comic']['title'] alt = refs[i]['comic']['alt'] if refs[i]['stat_tr']['status'] >= -1: transcript = XKCD.removeNoise (refs[i]['comic']['transcript']) complete_str = XKCD.removePunk('{} {} {}'.format(title, alt, transcript)) # Record the comic in the index XKCD.indexComic (complete_str, i, index, black_list) # save file if edited: with open (INDEX, 'w') as outfile: json.dump (index, outfile, indent = 4)
#!/usr/bin/python import sys sys.path.insert(0, '/home/nhatz/Code/bots/randi/python/lib') import json import client_helpers as CLIENT import xkcd_helpers as XKCD PREPATH = '/home/nhatz/Code/bots/randi/' REFS = PREPATH + 'json/xkcd.references.json' #INDEX = PREPATH + 'json/xkcd.index.json' INDEX = 'xkcd.index.json' BLACK_LIST = PREPATH + 'json/xkcd.common.json' index = dict() refs = CLIENT.loadJson(REFS) black_list = CLIENT.loadJson(BLACK_LIST) for i in list(refs.keys()): transcript = str() title = str() alt = str() complete_str = str() #FIXME: I really need to fix these magic numbers if refs[i]['stat_com']['status'] == 0: # Retrieve the comic info from the references title = refs[i]['comic']['title'] alt = refs[i]['comic']['alt'] if refs[i]['stat_tr']['status'] >= -1: transcript = XKCD.removeNoise(refs[i]['comic']['transcript'])
async def on_message(message): global xkcd_refs, xkcd_index if not message.content.startswith(wame_config['prefix']): if Wame.user.mentioned_in(message) and not message.mention_everyone \ and not len(message.content.split("@here")) > 1 \ and len(message.mentions) == 1: await Wame.send_message \ (message.channel, embed = wame_help) else: args = await CLIENT.parse_args(message.content, wame_config['prefix']) command = args[0] args = args[1:] logging.info ('\nFull mess: {}\nCommand : {}\nArgs : {}'\ .format (message.content, command, args)) if command == 'xkcd': tmp = await Wame.send_message(message.channel, 'Searching...') if len(args) is 0: embed_comic = await CLIENT.random_embed(xkcd_refs) await Wame.edit_message(tmp, ' ', embed=embed_comic) else: result = await CLIENT.search \ (' '.join(args), xkcd_index, xkcd_refs, blk_list) # 0 == comic found if result['status'] == 0: # Create embed embed_comic = await \ CLIENT.create_embed (result['comic']) await Wame.edit_message(tmp, ' ', embed=embed_comic) else: # It hasn't been found, too bad not_found = discord.Embed (description = "_I found nothing. I'm so sawry and sad :(_. \ \nReply with **`random`** for a surprise\n" , \ colour = (0x000000)) await Wame.edit_message(tmp, " ", embed=not_found) msg = await Wame.wait_for_message \ (author = message.author, \ content = "random", timeout = 20) if (msg): embed_comic = await CLIENT.random_embed(xkcd_refs) await Wame.send_message \ (message.channel, embed = embed_comic) else: await Wame.edit_message(tmp, "Timeout") elif command == 'random': embed_comic = await CLIENT.random_embed(xkcd_refs) await Wame.send_message(message.channel, embed=embed_comic) elif command == 'latest': online_latest = await CLIENT.get_online_xkcd() if online_latest['status'] is 0: embed_comic = await \ CLIENT.create_embed(online_latest) else: local_latest = xkcd_refs[str( max(map(lambda x: int(x), xkcd_refs.keys())))] embed_comic = await \ CLIENT.create_embed (local_latest) await Wame.send_message(message.channel, embed=embed_comic) elif command == 'report': bug_channel = Wame.get_channel(wame_config['report_channel']) embed_report = await CLIENT.report_embed (message, \ {'type': 'User', 'color': (0xff0000), 'client': Wame}) report = await Wame.send_message(bug_channel, embed=embed_report) await Wame.pin_message(report) elif command == 'update': from update_references import update_ref from index import update_index update_ref() xkcd_refs = CLIENT.loadJson(REF) update_index() xkcd_index = CLIENT.loadJson(INDEX) local_latest = xkcd_refs[str( max(map(lambda x: int(x), xkcd_refs.keys())))] embed_comic = await \ CLIENT.create_embed (local_latest) await Wame.send_message(message.channel, embed=embed_comic) elif command == 'help': await Wame.send_message (message.channel, \ embed = wame_help)
JSON = PATH['json'] # Yep you should rename your config.json and append priv to it # This way you won't add even more private stuff on github CONFIG = JSON + "xkcd.config.json.priv" INDEX = JSON + "xkcd.index.json" REF = JSON + "xkcd.references.json" BL = JSON + "xkcd.common.json" logging.basicConfig(level=logging.INFO) wame_config = dict() xkcd_index = dict() xkcd_refs = dict() wame_config = CLIENT.loadJson(CONFIG) xkcd_index = CLIENT.loadJson(INDEX) xkcd_refs = CLIENT.loadJson(REF) blk_list = CLIENT.loadJson(BL) wame_help = discord.Embed \ (title = wame_config['help']['title'], \ colour = discord.Colour(0x123654), \ url = wame_config['help']['url'], \ description = wame_config['help']['description']) wame_help.set_footer (text = wame_config['help']['footer'], \ icon_url = wame_config['help']['icon_url']) Wame = discord.Client() wgame = discord.Game(name=wame_config['game'])
import json with open('../client/xkcd.path.json.priv') as path_file: PATH = json.load(path_file) sys.path.insert(0, PATH['lib']) import client_helpers as CLIENT import xkcd_helpers as XKCD PREPATH = PATH['json'] REFS = PREPATH + 'xkcd.references.json' INDEX = PREPATH + 'xkcd.index.json' BLACK_LIST = PREPATH + 'xkcd.common.json' index = dict () black_list = CLIENT.loadJson (BLACK_LIST) edited = False def update_index(references=REFS): global edited, index refs = CLIENT.loadJson (REFS) for i in list(refs.keys ()): transcript = str () title = str () alt = str () complete_str = str () #FIXME: I really need to fix these magic numbers if refs[i]['stat_com']['status'] == 0: edited = True
try: import client_helpers as CLIENT from command import CommandManager except ImportError: print('Error: One or more modules were not found in path.') exit(2) JSON = PATH['json'] # Yep you should rename your config.json and append priv to it # This way you won't add even more private stuff on github CONFIG = JSON + "priv.nhk.config.json" COMMANDS = JSON + "nhk.command.json" logging.basicConfig(level=logging.INFO) nhatz_config = CLIENT.loadJson(CONFIG) commands = CLIENT.loadJson(COMMANDS) censored = nhatz_config['censored'] Nhatz = discord.Client() last_msg = dict() comanager = CommandManager(Nhatz, commands, nhatz_config) def record_message(msg): if msg.channel.id in comanager.last_msg: comanager.last_msg[msg.channel.id].put(msg) else: comanager.last_msg[msg.channel.id] = queue.LifoQueue() comanager.last_msg[msg.channel.id].put(msg)
# It's not too much of an issue if it's not there; it will be created. # We hope the base db with the imported blacklist exists, though. db = Collection(JSON + 'collection.sqlite') # Yep you should rename your config.json and append priv to it # This way you won't add even more private stuff on github CONFIG = JSON + "xkcd.config.json.priv" # This is displayed to the channel if requests need comics but # the collection is empty. EMPTY_COLLECTION_MSG = "My collection is empty :(" logging.basicConfig (level = logging.INFO) wame_config = CLIENT.loadJson (CONFIG) wame_help = discord.Embed \ (title = wame_config['help']['title'], \ colour = discord.Colour(0x123654), \ url = wame_config['help']['url'], \ description = wame_config['help']['description']) wame_help.set_footer (text = wame_config['help']['footer'], \ icon_url = wame_config['help']['icon_url']) Wame = discord.Client () wgame = discord.Game (name = wame_config['game']) @Wame.event async def on_ready (): await Wame.change_presence (game = wgame)
try: with open(sys.argv[1]) as path_file: PATH = json.load(path_file) except: print('Unable to open file {}'.format(sys.argv[1])) exit(2) else: print("Usage: python wamior.py /path/to/path.json") exit(1) sys.path.insert(0, PATH['lib']) import client_helpers as CLIENT import parser_helpers as PARSER CONFIG = dict() CONFIG = CLIENT.loadJson(PATH['config']) logging.basicConfig(level=logging.INFO) Wame = discord.Client() wgame = discord.Game(name=CONFIG['game']) @Wame.event async def on_ready(): await Wame.change_presence(game=wgame) bug_channel = Wame.get_channel(CONFIG['report_channel']) CLIENT.greet(Wame, channel=bug_channel) @Wame.event