当前位置: 首页>>代码示例>>Python>>正文


Python formatting.color函数代码示例

本文整理汇总了Python中willie.formatting.color函数的典型用法代码示例。如果您正苦于以下问题:Python color函数的具体用法?Python color怎么用?Python color使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了color函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: default_mask

def default_mask(trigger):
    welcome = formatting.color('Benvenuto su:', formatting.colors.PURPLE)
    chan = formatting.color(trigger.sender, formatting.colors.TEAL)
    topic_ = formatting.bold('Topic:')
    topic_ = formatting.color('| ' + topic_, formatting.colors.PURPLE)
    arg = formatting.color('{}', formatting.colors.GREEN)
    return '{} {} {} {}'.format(welcome, chan, topic_, arg)
开发者ID:neslinesli93,项目名称:willie,代码行数:7,代码来源:adminchannel.py

示例2: ytsearch

def ytsearch(bot, trigger):
    """
    .youtube <query> - Search YouTube
    """
    if not trigger.group(2):
        return
    uri = 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&q=' + trigger.group(2)
    raw = web.get(uri + '&key=' + bot.config.google.public_key)
    vid = json.loads(raw)['items'][0]['id']['videoId']
    uri = 'https://www.googleapis.com/youtube/v3/videos?id=' + vid + '&part=contentDetails,snippet,statistics'
    video_info = ytget(bot, trigger, uri)
    if video_info is None:
        return

    message = ('[YT Search]' +
              ' Title: ' + video_info['snippet']['title'] +
              ' | Uploader: ' + video_info['snippet']['channelTitle'] +
              ' | Uploaded: ' + video_info['snippet']['publishedAt'] +
              ' | Duration: ' + video_info['contentDetails']['duration'] +
              ' | Views: ' + video_info['statistics']['viewCount'] +
              ' | Comments: ' + video_info['statistics']['commentCount'] +
              ' | ' + color(video_info['statistics']['likeCount'] + '+', colors.GREEN) +
              ' | ' + color(video_info['statistics']['dislikeCount'] + '-', colors.RED) +
              ' | Link: https://youtu.be/' + video_info['id'])

    bot.say(message)
开发者ID:Inari-Whitebear,项目名称:inumuta-modules,代码行数:26,代码来源:youtube.py

示例3: speakthetruth

def speakthetruth(bot, trigger, found_match=None):

	n = random.randint(0, 1)

	if n == 0:
		s = []
		s.append("it's pretty obvious the answer is no")
		s.append("negative")
		s.append("NO")
		s.append("obviously not")
		s.append("shake my head to be honest fam")
		s.append("my sources say no")
		msg = color(random.choice(s), '04')

	else:
		s = []
		s.append("that's certainly so")
		s.append("i have no doubt in my mind")
		s.append("YES")
		s.append("of course")
		s.append("it is certain")
		s.append("one would be wise to think so")
		msg = color(random.choice(s), '03')

	bot.action('shakes the magic 8 ball... ' + msg)
开发者ID:magicksid,项目名称:willie-modules,代码行数:25,代码来源:8ball.py

示例4: osu_user

def osu_user(bot, trigger):
    """
    .osu [user] - Show information on an osu! user
    """
    data = '?k=%s&u=%s' % (bot.config.osu.api_key, str(trigger.group(2)))
    #bot.say(url)
    raw = web.get('https://osu.ppy.sh/api/get_user'+data)
    response = json.loads(raw)
    if not response[0]:
        bot.say('['+color('osu!', u'13')+'] '+'Invalid user')
        return
    user = response[0]
    output = [
        '[', color('osu!', u'13'), '] ',
        user['username'],
        ' | Level ',
        str(int(float(user['level']))),
        ' | Rank ',
        user['pp_rank'],
        ' | Play Count ',
        user['playcount'],
        ' | Ranked Score ',
        user['ranked_score'],
        ' | Total Score ',
        user['total_score'],
        ' | Accuracy ~',
        str(int(float(user['accuracy']))),
        '%'
    ]
    bot.say(''.join(output))
开发者ID:meew0,项目名称:inumuta-modules,代码行数:30,代码来源:osu.py

示例5: get_data

def get_data(bot, trigger, URL):
    URL = URL.split('#')[0]
    try:
        raw = fetch_api_endpoint(bot, URL)
        rawLang = fetch_api_endpoint(bot, URL + '/languages')
    except HTTPError:
        bot.say('[Github] API returned an error.')
        return NOLIMIT
    data = json.loads(raw)
    langData = json.loads(rawLang).items()
    langData = sorted(langData, key=operator.itemgetter(1), reverse=True)

    if 'message' in data:
        return bot.say('[Github] %s' % data['message'])

    langColors = deque(['12', '08', '09', '13'])

    max = sum([pair[1] for pair in langData])

    data['language'] = ''
    for (key, val) in langData[:3]:
        data['language'] = data['language'] + color(str("{0:.1f}".format(float(val) / max * 100)) + '% ' + key, langColors[0]) + ' '
        langColors.rotate()

    if len(langData) > 3:
        remainder = sum([pair[1] for pair in langData[3:]])
        data['language'] = data['language'] + color(str("{0:.1f}".format(float(remainder) / max * 100)) + '% Other', langColors[0]) + ' '

    timezone = get_timezone(bot.db, bot.config, None, trigger.nick)
    if not timezone:
        timezone = 'UTC'
    data['pushed_at'] = format_time(bot.db, bot.config, timezone, trigger.nick, trigger.sender, from_utc(data['pushed_at']))

    return data
开发者ID:Inari-Whitebear,项目名称:inumuta-modules,代码行数:34,代码来源:github.py

示例6: osu_beatmap

def osu_beatmap(bot, trigger):
    data = '?k=%s&%s=%s' % (bot.config.osu.api_key, str(trigger.group(1)), str(trigger.group(2)))
    #bot.say(url)
    raw = web.get('https://osu.ppy.sh/api/get_beatmaps' + data)
    topscore = None
    if trigger.group(1) == 'b':
        rawscore = web.get('https://osu.ppy.sh/api/get_scores' + data)
        topscore = json.loads(rawscore)[0]
    response = json.loads(raw)
    if not response[0]:
        bot.say('[' + color('osu!', u'13') + '] ' + ' Invalid link')
        return
    beatmap = response[0]
    m, s = divmod(int(beatmap['total_length']), 60)
    output = [
        '[', color('osu!', u'13'), '] ',
        beatmap['artist'],
        ' - ',
        beatmap['title'],
        ' (Mapped by ',
        beatmap['creator'],
        ') | ',
        str(m), 'm, ', str(s), 's',
        ' | ',
        beatmap['version'],
        ' | Difficulty: ',
        beatmap['difficultyrating'],
        ' | ',
        beatmap['bpm'],
        ' BPM'
    ]
    if topscore:
        output += (' | High Score: ' + topscore['score'] + ' (' + topscore['rank'] + ') - ' + topscore['username'])
    bot.say(''.join(output))
开发者ID:Inari-Whitebear,项目名称:inumuta-modules,代码行数:34,代码来源:osu.py

示例7: ud_search

def ud_search(bot, trigger):
    query = trigger.group(2).strip()
    
    url = 'http://api.urbandictionary.com/v0/define?term=%s' %(query.encode('utf-8'))
    #bot.say(url)
    try:
      response = web.get_urllib_object(url, 20)
    except UnicodeError:
      bot.say('[UrbanDictionary] ENGLISH MOTHERFUCKER, DO YOU SPEAK IT?')
      return
    else:
      data = json.loads(response.read())
      #bot.say(str(data))
    try:
      definition = data['list'][0]['definition'].replace('\n', ' ')
    except KeyError:
      bot.say('[UrbanDictionary] Something went wrong bruh')
    except IndexError:
      bot.say('[UrbanDictionary] No results, do you even spell bruh?')
    else:
      thumbsup = color(str(data['list'][0]['thumbs_up'])+'+', u'03')
      thumbsdown = color(str(data['list'][0]['thumbs_down'])+'-', u'04')
      permalink = data['list'][0]['permalink']
      length = len(thumbsup)+len(thumbsdown)+len(permalink)+35
      ellipsies = ''
      if (len(definition)+length) > 445:
        ellipsies = '...'
      udoutput = "[UrbanDictionary] %s; %.*s%s | %s >> %s %s" % (query, 445-length, definition, ellipsies, permalink, thumbsup, thumbsdown)
      if not "spam spam" in udoutput:
          bot.say(udoutput)
      else:
          bot.say('[UrbanDictionary] Negative ghostrider')
开发者ID:meew0,项目名称:inumuta-modules,代码行数:32,代码来源:urbandictionary.py

示例8: rip

def rip(bot, trigger, found_match=None):
    arg = " ".join(trigger[4:50].split()).strip()
    if arg == "":
        return
    bot.say(
        color(u"✞" + " " + u"✞" + " " u"✞" + " " u"✞" + " ", "04", "00")
        + color(" " + arg.upper() + " ", "00", "04")
        + color(" " + u"✞" + " " + u"✞" + " " u"✞" + " " u"✞", "04", "00")
    )
开发者ID:madprops,项目名称:willie-modules,代码行数:9,代码来源:rip.py

示例9: rpost_info

def rpost_info(bot, trigger, match=None):
    r = praw.Reddit(user_agent=USER_AGENT)
    match = match or trigger
    s = r.get_submission(url=match.group(1))

    message = (
        "[REDDIT] {title} {link}{nsfw} | {points} points ({percent}) | "
        "{comments} comments | Posted by {author} | "
        "Created at {created}"
    )

    if s.is_self:
        link = "(self.{})".format(s.subreddit.display_name)
    else:
        link = "({}) to r/{}".format(s.url, s.subreddit.display_name)

    if s.over_18:
        nsfw = bold(color(" [NSFW]", colors.RED))
        sfw = bot.db.get_channel_value(trigger.sender, "sfw")
        if sfw:
            link = "(link hidden)"
            bot.write(["KICK", trigger.sender, trigger.nick, "Linking to NSFW content in a SFW channel."])
    else:
        nsfw = ""

    if s.author:
        author = s.author.name
    else:
        author = "[deleted]"

    tz = time.get_timezone(bot.db, bot.config, None, trigger.nick, trigger.sender)
    time_created = dt.datetime.utcfromtimestamp(s.created_utc)
    created = time.format_time(bot.db, bot.config, tz, trigger.nick, trigger.sender, time_created)

    if s.score > 0:
        point_color = colors.GREEN
    else:
        point_color = colors.RED

    percent = color(unicode(s.upvote_ratio * 100) + "%", point_color)

    h = HTMLParser.HTMLParser()
    message = message.format(
        title=h.unescape(s.title),
        link=link,
        nsfw=nsfw,
        points=s.score,
        percent=percent,
        comments=s.num_comments,
        author=author,
        created=created,
    )

    bot.say(message)
开发者ID:andrejsavikin,项目名称:inumuta-modules,代码行数:54,代码来源:reddit.py

示例10: rpost_info

def rpost_info(bot, trigger, match=None):
    r = praw.Reddit(user_agent=USER_AGENT)
    match = match or trigger
    s = r.get_submission(url=match.group(1))

    if (comment_regex.match(match.group(0))):
        return rcomment_info(bot, trigger, s)

    message = ('[REDDIT] {title} {link}{nsfw} | {points} points ({percent}) | '
               '{comments} comments | Posted by {author} | '
               'Created at {created}')

    if s.is_self:
        link = '(self.{})'.format(s.subreddit.display_name)
    else:
        link = '({}) to /r/{}'.format(s.url, s.subreddit.display_name)

    if s.over_18:
        nsfw = bold(color(' [NSFW]', colors.RED))
        sfw = bot.db.get_channel_value(trigger.sender, 'sfw')
        if sfw:
            link = '(link hidden)'
            bot.write(['KICK', trigger.sender, trigger.nick,
                       'Linking to NSFW content in a SFW channel.'])
    else:
        nsfw = ''

    if s.author:
        author = s.author.name
    else:
        author = '[deleted]'

    tz = time.get_timezone(bot.db, bot.config, None, trigger.nick,
                           trigger.sender)
    time_created = dt.datetime.utcfromtimestamp(s.created_utc)
    created = time.format_time(bot.db, bot.config, tz, trigger.nick,
                               trigger.sender, time_created)

    if s.score > 0:
        point_color = colors.GREEN
    else:
        point_color = colors.RED

    percent = color(unicode(s.upvote_ratio * 100) + '%', point_color)

    h = HTMLParser.HTMLParser()
    message = message.format(
        title=h.unescape(s.title), link=link, nsfw=nsfw, points=s.score, percent=percent,
        comments=s.num_comments, author=author, created=created)

    bot.say(message)
开发者ID:Inari-Whitebear,项目名称:inumuta-modules,代码行数:51,代码来源:reddit.py

示例11: niniit

def niniit(bot, trigger, found_match=None):

	gn = "Good night everyone! "

	msgs = []
	msgs.append("May you dream of lolis!")
	msgs.append("Let tomorrow be a great day!")
	msgs.append("Good luck!")
	msgs.append("Sleep tight puppers!")
	msgs.append("Please don't die!")
	msgs.append("I'll be back!")
	msgs.append("It's being fun!")

	msg = gn + random.choice(msgs)

	bot.say(color(u"🌙 ", '06', '00') + color(msg, '06', '00') + color(u" 🌙", '06', '00'))	
开发者ID:madprops,项目名称:willie-modules,代码行数:16,代码来源:nini.py

示例12: announce

def announce(type, o, repo):
    name = {'commits': 'Commit', 'issues': 'Bug-Report', 'pull': 'Pull-Request'}
    if "pull_request" in o:
        type = "pull"
    msg = "Neuer " + name[type] + " in " + repo + " von "
    msg += (o.get("user", {}).get("login", None) or o.get("commit", {}).get("author", {}).get("name", None) or "???")
    msg += ": " + formatting.color((o.get("title", None) or o.get("commit", {}).get("message", None) or "?"), "white", "black")
    msg += "( " + o["html_url"] + " )"
    return msg
开发者ID:bauerj,项目名称:watch-repository-plugin,代码行数:9,代码来源:watch-repository.py

示例13: trump

def trump(bot, trigger, found_match=None):
	arg = trigger.group(2)
	if arg:
		thing = arg.upper()
	else:
		thing = 'AMERICA'
	msg = '  MAKE ' + thing + ' GREAT AGAIN!  T R U M P   2 0 1 6  '
	msg = u'\x02' + color(msg, '04', '00') + u'\x02'
	bot.say(msg)
开发者ID:madprops,项目名称:willie-modules,代码行数:9,代码来源:trump.py

示例14: start

def start(bot, trigger):
    """
    Put a bomb in the specified user's pants. They will be kicked if they
     don't guess the right wire fast enough.
    """
    if not trigger.group(3):
        bot.say("Who do you want to bomb?")
        return NOLIMIT
    if bot.db.get_channel_value(trigger.sender, 'bombs_disabled'):
        bot.notice("An admin has disabled bombing in %s." % trigger.sender, trigger.nick)
        return NOLIMIT
    since_last = time_since_bomb(bot, trigger.nick)
    if since_last < TIMEOUT and not trigger.admin:
        bot.notice("You must wait %.0f seconds before you can bomb someone again." % (TIMEOUT - since_last),
                   trigger.nick)
        return
    global BOMBS
    target = Identifier(trigger.group(3))
    target_unbombable = bot.db.get_nick_value(target, 'unbombable')
    if target == bot.nick:
        bot.say("You thought you could trick me into bombing myself?!")
        return NOLIMIT
    if target == trigger.nick:
        bot.say("%s pls. Bomb a friend if you have to!" % trigger.nick)
        return NOLIMIT
    if target.lower() not in bot.privileges[trigger.sender.lower()]:
        bot.say("You can't bomb imaginary people!")
        return NOLIMIT
    if target_unbombable and not trigger.admin:
        bot.say("I'm not allowed to bomb %s, sorry." % target)
        return NOLIMIT
    if bot.db.get_nick_value(trigger.nick, 'unbombable'):
        bot.say("Try again when you're bombable yourself, %s." % trigger.nick)
        return NOLIMIT
    with lock:
        if target.lower() in BOMBS:
            bot.say("I can't fit another bomb in %s's pants!" % target)
            return NOLIMIT
        wires = [COLORS[i] for i in sorted(sample(xrange(len(COLORS)), randrange(3, 5)))]
        num_wires = len(wires)
        wires_list = [formatting.color(str(wire), str(wire)) for wire in wires]
        wires_list = ", ".join(wires_list[:-2] + [" and ".join(wires_list[-2:])]).replace('Light_', '')
        wires = [wire.replace('Light_', '') for wire in wires]
        color = choice(wires)
        bot.say("Hey, %s! I think there's a bomb in your pants. %s timer, %d wires: %s. "
                "Which wire would you like to cut? (respond with %scutwire color)"
                % (target, FUSE_TEXT, num_wires, wires_list, bot.config.core.help_prefix or '.'))
        bot.notice("Hey, don't tell %s, but it's the %s wire." % (target, color), trigger.nick)
        if target_unbombable:
            bot.notice("Just so you know, %s is marked as unbombable." % target, trigger.nick)
        timer = Timer(FUSE, explode, (bot, trigger))
        BOMBS[target.lower()] = (wires, color, timer, target)
        timer.start()
    bombs_planted = bot.db.get_nick_value(trigger.nick, 'bombs_planted') or 0
    bot.db.set_nick_value(trigger.nick, 'bombs_planted', bombs_planted + 1)
    bot.db.set_nick_value(trigger.nick, 'bomb_last_planted', time.time())
开发者ID:Phr33d0m,项目名称:willie-BombBot,代码行数:56,代码来源:bombbot.py

示例15: error

def error(bot, msg):
    print("{}: {}".format(str(datetime.datetime.now()), msg))

    if "initialized" in bot.memory:
        if "last_error_msg" not in bot.memory["ff"] or bot.memory["ff"]["last_error_msg"] != msg:
            bot.memory["ff"]["last_error_msg"] = msg
            bot.msg(
                bot.config.freifunk.change_announce_target,
                formatting.color("{}: {}".format(formatting.bold("[ERROR]"), msg), formatting.colors.RED),
            )
开发者ID:ffka,项目名称:ffka-irc-bot,代码行数:10,代码来源:ff-nodeinfo_meshviewer.py


注:本文中的willie.formatting.color函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。