def sendHelp(message): cmdList = h.getXmlTree('commands') toReturn = "" #No attempted arguments sent, so send list of commands if re.search("\[|\]", message.content) == None: toReturn = "Here are my commands:\n" info = {"name": "**Information:**", "inline": "true", "value": ""} useful = {"name": "**Useful:**", "inline": "true", "value": ""} fun = {"name": "**Fun:**", "inline": "true", "value": ""} for cmd in cmdList.findall("./function"): if not h.isDisabled(cmd.find("command").text): if cmd.get("category") == "information": info['value'] = info['value'] + " `{}`\n".format( cmd.find("format").text) elif cmd.get("category") == "useful": useful['value'] = useful['value'] + " `{}`\n".format( cmd.find("format").text) elif cmd.get("category") == "fun": fun['value'] = fun['value'] + " `{}`\n".format( cmd.find("format").text) toReturn = embeddable.Embeddable() toReturn.addField(info, useful, fun) toReturn.setFooter(c.HELP_REMINDER) else: try: #Specific request arg = h.parseArgs(message.content, "help", 1, 1) for i in set(arg): arg = i.lower() #Change back to string if (arg.startswith("!")): arg = arg[1:] cmd = cmdList.find("./function/[command='{}']".format(arg)) if cmd == None: raise errors.CustomCommandException("help", "bad_command") elif h.isDisabled(cmd.find("command").text): toReturn = "Sorry, the command you're trying to find help for is disabled." else: toReturn = "Here's how to use `!{}`:\n".format( cmd.find("command").text) for b in cmd.findall("body"): toReturn = toReturn + "\n" + b.find( "description").text + "\n" for i in b.findall("hint"): toReturn = toReturn + h.blockQuote( "\N{BULLET} " + h.formatProps(cmd.find("command").text, i.text)) toReturn = embeddable.empty(toReturn) except errors.Error as e: raise e return toReturn
def __formatArticle(article): title = article['title'] description = article['description'] extract = article['extract'] url = article['content_urls']['desktop']['page'] if "thumbnail" in article: imageUri = article['thumbnail']['source'] else: imageUri = "" textBox = description + "\n-----\n" + extract toReturn = embed.Embeddable(url=url, title=title, text=textBox, image=imageUri) toReturn.setFooter("Powered by Wikipedia.org") return toReturn
def sayHello(): timeField = {'name': 'Uptime', 'value': ''} cmdField = {'inline': 'true', 'name': 'Most popular commands', 'value': ''} procField = { 'inline': 'true', 'name': 'Currently running timers', 'value': '' } changeField = {'name': 'Latest changes', 'value': ''} linkField = {'name': 'Full list of changes', 'value': c.HELLO_CHANGELOG} timeField['value'] = h.formatTime(h.getTime(), offset=g.begin) cmds = h.getTopCommands() for cmd, count in cmds.items(): percent = "({}\%)".format(int((count / g.totalCommands) * 100)) cmdField['value'] += ("\N{BULLET} `!{}` - used {} {}\n".format( cmd, h.pluralize(count, "time"), percent)) procField['value'] = "\N{BULLET} " + h.pluralize(h.getNumReminders(), "reminder") procField['value'] += "\n\N{BULLET} " + h.pluralize( len(g.activePolls), "poll") changeList = h.getXmlTree('changelogs').find( "./version/[@num='{}']".format(c.VERSION)) if changeList is None: changeField['value'] = "\n*No changes were found.*" else: for change in changeList.findall('change'): changeField['value'] += "\n\N{BULLET} %s" % change.text emb = embeddable.Embeddable(url=c.HELLO_URL, title="FunkyBot v%s" % c.VERSION) emb.addField(timeField, cmdField, procField, changeField, linkField) emb.setThumbnail(str(g.client.user.avatar_url)) emb.setFooter(c.HELLO_HELP) return emb
def __formatResult(newUri, siteUrl): params = { 'api_key': g.props['giantbomb_key'], 'format': 'json', 'field_list': 'deck,developers,genres,image,name,original_release_date,platforms,publishers,similar_games' } try: response = requests.get(url=newUri, headers=g.apiHeaders, params=params) gameResult = response.json() except Exception as e: raise title = gameResult['results']['name'] text = gameResult['results']['deck'] imageUri = gameResult['results']['image']['medium_url'] toReturn = embed.Embeddable(url=siteUrl, title=title, text=text, image=imageUri) #Grab genres genreField = {"inline": "true", "name": "Genre", "value": ""} if 'genres' not in gameResult['results']: genreField['value'] = "No genre information found" else: for r in gameResult['results']['genres']: genreField['value'] += r['name'] + ", " genreField['value'] = genreField['value'][:-2] #Grab release date releaseField = {"inline": "true", "name": "Release date", "value": ""} if gameResult['results']['original_release_date'] == None: releaseField['value'] = "Not currently released" else: tmp = gameResult['results']['original_release_date'] tmp = dt.strptime(tmp, '%Y-%m-%d').strftime('%b %d, %Y') releaseField['value'] = tmp #Grab platforms platField = {"name": "Playable on", "value": ""} if gameResult['results']['platforms'] == None: platField['value'] = "No platform information found" else: for p in gameResult['results']['platforms']: platField['value'] += p['name'] + ", " platField['value'] = platField['value'][:-2] #Grab developers devField = {"inline": "true", "name": "Developers", "value": ""} if gameResult['results']['developers'] == None: devField['value'] = "No developer information found" else: for d in gameResult['results']['developers']: devField['value'] += d['name'] + ", " devField['value'] = devField['value'][:-2] #Grab publishers pubField = {"inline": "true", "name": "Publishers", "value": ""} if gameResult['results']['publishers'] == None: pubField['value'] = "No publisher information found" else: for p in gameResult['results']['publishers']: pubField['value'] += p['name'] + ", " pubField['value'] = pubField['value'][:-2] #Grab similar games similarField = {"name": "Here are some similar games:", "value": ""} if gameResult['results']['similar_games'] == None: similarField[ 'value'] = "Sorry, I couldn't find any similar games to this one." else: for s in range(min(3, len(gameResult['results']['similar_games']))): similarField['value'] += ( gameResult['results']['similar_games'][s]['name'] + ", ") similarField['value'] = similarField['value'][:-2] toReturn.addField(genreField, releaseField, platField, devField, pubField, similarField) toReturn.setFooter("Powered by GiantBomb.com") return toReturn
def __formatCard(card, givenUri=None, givenPrice=None, givenColor=None, givenSetCode=None): name = card['name'] cost = "" textBox = "" imageUri = "" price = "No price info found" color = 0 setCode = "" toReturn = [] if givenUri == None: uri = card['scryfall_uri'] else: uri = givenUri if givenPrice == None: if 'prices' in card and card['prices'][g.props['magic_currency']] != None: price = card['prices'][g.props['magic_currency']] if g.props['magic_currency'] == 'usd': price = "$" + price elif g.props['magic_currency'] == 'eur': price = "€" + price elif g.props['magic_currency'] == 'tix': price = price + " TIX" else: price = givenPrice if givenColor == None: color = __colorEmbed(card) else: color = givenColor if givenSetCode == None: setCode = card['set'].upper() else: setCode = givenSetCode if 'card_faces' in card: if card['layout'] == "transform" or card['layout'] == "modal_dfc": cost = card['card_faces'][0]['mana_cost'] for f in card['card_faces']: toReturn.append(__formatCard(f, givenUri=uri, givenPrice=price, givenColor=color, givenSetCode=setCode)) else: imageUri = card['image_uris']['normal'] toReturn = emb.Embeddable( url=uri, title=name + " " + cost, image=imageUri) for f in card['card_faces']: fieldName = "**" + f['name'] + " " + f['mana_cost'] + "**" fieldText = __makeTextBox(f) toReturn.addField({"name": fieldName, "value": fieldText, "inline": "true"}) toReturn.setColor(color) toReturn.setFooter(setCode + " | " + price + " | Powered by Scryfall.com") else: textBox = __makeTextBox(card) cost = card['mana_cost'] imageUri = card['image_uris']['normal'] if 'prices' in card and card['prices'][g.props['magic_currency']] != None: price = card['prices'][g.props['magic_currency']] if g.props['magic_currency'] == 'usd': price = "$" + price elif g.props['magic_currency'] == 'eur': price = "€" + price toReturn = emb.Embeddable( url=uri, title=name + " " + cost, text=textBox, image=imageUri) toReturn.setColor(color) toReturn.setFooter(setCode + " | " + price + " | Powered by Scryfall.com") return toReturn