Exemple #1
0
def main(bot, author_id, message, thread_id, thread_type, **kwargs):
    global card_made
    if not card_made:
        gex.gex_create(CARD_NAME, [bot.uid, CIAN_ID], CARD_DESC)
        gex.gex_set_image(bot.uid, CARD_NAME, CARD_IMAGE)
        card_made = True

    message_words = {w.lower().strip(punctuation) for w in message.split()}
    if message_words & BAD_WORDS:
        gex.gex_give(bot.uid, CARD_NAME, author_id)
        return True
    return False
Exemple #2
0
def _check_for_battle_finish(bot, battle_id):
    matching_battles = BATTLE_DB.search(BATTLE.id == battle_id)
    battle = matching_battles[0]
    if 'finished' in battle and battle['finished']:
        return
    winner, loser = None, None
    if battle['attacker']['power'] <= 0 or len(
            battle['attacker']['deck']) == 0:
        # attacker lost
        winner = battle['defender']['id']
        loser = battle['attacker']['id']
    elif battle['defender']['power'] <= 0 or len(
            battle['defender']['deck']) == 0:
        # defender lost
        winner = battle['attacker']['id']
        loser = battle['defender']['id']
    else:
        return
    winner_name = gex_util.user_id_to_name(bot, winner)
    loser_name = gex_util.user_id_to_name(bot, loser)
    thread_id = battle['thread_id']
    thread_type = ThreadType.GROUP if battle[
        'is_group_thread'] else ThreadType.USER
    out = '_{}_ won battle `{}` against _{}_'.format(winner_name, battle_id,
                                                     loser_name)
    bot.sendMessage(out, thread_id=thread_id, thread_type=thread_type)

    # Set battle as finished.
    battle['finished'] = True
    BATTLE_DB.update(battle, BATTLE.id == battle_id)

    # Assign cards for winning and losing.
    NOAH_ID = '100003244958231'
    MASTERS = [bot.uid, NOAH_ID]
    # TODO(iandioch): Make it possible to assume a card exists.
    try:
        gex.gex_create('battle_won', MASTERS, 'I won a gex battle!')
    except Exception as e:
        pass
    try:
        gex.gex_create('battle_lost', MASTERS, 'I lost a gex battle >:(')
    except Exception as e:
        pass
    print('Giving gex cards for winning and losing battle.')
    gex.gex_give(bot.uid, 'battle_won', winner)
    gex.gex_give(bot.uid, 'battle_lost', loser)
Exemple #3
0
def handle_gex_sell_cards(bot, user_id, ticker, profit):
    NOAH_ID = '100003244958231'
    MIN_TICKER_CARD_DELTA = 25
    ticker_cards = [
        ('dcth', 'I traded the meme stock'),
        ('aapl', 'I drank a cupertino of the kool aid'),
        ('goog', 'I only know like one stock ticker symbol'),
        ('snap', 'I am the hot dog'),
        ('nvda', 'Green is the warmest colour'),
        ('amd',
         'The Red Army and Navy and the whole Soviet people must fight for every inch of Soviet soil, fight to the last drop of blood for our towns and villages...onward, to victory!'
         ),
    ]
    cards = ticker_cards[:]
    vals = [2000, 1500, 1000, 750, 500, 250, 100]
    for v in vals:
        cards.append(('{}-gain'.format(v),
                      'I earned {} lindens in one sell xo'.format(v)))
        cards.append(('{}-loss'.format(v),
                      'I dropped a bag of {} lindens :('.format(v)))

    # try to create badges if they don't already exist
    for card_id, desc in cards:
        try:
            gex.gex_create(card_id, [REED_ID, NOAH_ID], desc)
        except RuntimeError as e:
            print('Could not create card:', e)

    # give ticker cards
    for card_id, desc in ticker_cards:
        if card_id.upper() == ticker and abs(profit) >= MIN_TICKER_CARD_DELTA:
            gex.gex_give(REED_ID, card_id, user_id)

    # give profit & loss cards
    for val in vals:
        if profit > val:
            gex.gex_give(REED_ID, '{}-gain'.format(val), user_id)
        if profit < -val:
            gex.gex_give(REED_ID, '{}-loss'.format(val), user_id)