示例#1
0
#!/usr/bin/env python3

import logging

from tinydb import Query
from tinydb.operations import increment
from utils import new_database

from plugin import PluginManager

__author__ = 'sentriz'
COMMAND = None
CMD_DB = new_database('stats')
CMD = Query()
TILDA_DB = new_database('quote')
TILDA = Query()
COMMAND_IDENTIFIERS = set(['.', '~', '/'])

LOGGER = logging.getLogger("plugins.stats")
LOGGER.setLevel(logging.INFO)


def first_word_of(message):
    if ' ' in message:
        message = message.split()[0]
    return message


def is_tilda_command(command):
    return bool(TILDA_DB.search(TILDA.cmd == command))
示例#2
0
from fbchat.models import ThreadType
from plugins import gex
from random import shuffle
from tinydb import Query
from utils import new_database
import plugins._gex_action as gex_action
import plugins._gex_util as gex_util
import uuid

BATTLE_DB = new_database('gex_battle')
BATTLE = Query()

# The number of cards coming up in the deck that users can see.
NUM_UPCOMING_CARDS_TO_DISPLAY = 5
# The amount of power each user starts with in a battle.
STARTING_POWER_AMOUNT = 50


def _get_participant_info(bot, data):
    name = gex_util.user_id_to_name(bot, data['id'])
    deck = data['deck']
    ready = data['ready']
    power = data['power']
    return (name, deck, ready, power)

'''Get a permutation of a user's cards.'''


def _get_shuffled_deck(user_id):
    user_data = gex_util.get_user(user_id)
    print(user_data)
示例#3
0
文件: stats.py 项目: devoxel/steely
#!/usr/bin/env python3
'''
show plugin stats
'''

from formatting import *
from operator import itemgetter
from tinydb import Query
from utils import new_database

__author__ = 'sentriz'
COMMAND = 'stats'
CMD_DB = new_database('stats')
CMD = Query()
LIMIT = 10


def parse_stats(stats):
    for stat in CMD_DB.all():
        yield stat['command'], stat['count']


def sort_stats(stats):
    return sorted(stats, key=itemgetter(1), reverse=True)


def main(bot, author_id, message, thread_id, thread_type, **kwargs):
    clean_stats = list(parse_stats(CMD_DB))
    sorted_stats = sort_stats(clean_stats)[:LIMIT]
    max_command = max(len(command) for command, count in sorted_stats)
    message = f'top {LIMIT}\n――――――\n'
示例#4
0
.bug info <bug title>
.bug list

bug titles can't be longer than 45 chars

TODO: Add bug delete, bug modify, bug close and bug comment
'''

from tinydb import Query
import formatting
from utils import new_database

__author__ = 'devoxel'
COMMAND = 'bug'
ERR_MSG = "i'm sorry sam.. i'm afraid I can't do that."
BUG_DB = new_database('bug')
Bug = Query()


def get_bug(search):
    # first try by id
    try:
        s = BUG_DB.get(doc_id=int(search))
    except ValueError:
        s = BUG_DB.get(Bug.title == search)
    return s


def get_bug_info(command):
    command = command.split(maxsplit=1)
    if len(command) != 2:
示例#5
0
import time
from tinydb import Query
from plugins import gex
from utils import new_database

USER_DB = new_database('gex_users')
USER = Query()
CARD_DB = new_database('gex_cards')
CARD = Query()

# Cache to map facebook IDs to real names.
ID_TO_NAME = {}


def user_name_to_id(bot, name):
    print('user_name_to_id(bot, {})'.format(name))
    users = bot.searchForUsers(name)
    print("Searched for", name, "got", users)
    return users['id']


def user_id_to_name(bot, user_id):
    if user_id in ID_TO_NAME:
        print('Cache hit for {} in user_id_to_name'.format(user_id))
        return ID_TO_NAME[user_id]
    try:
        users = bot.fetchUserInfo(user_id)
        if len(users) == 0:
            raise ValueError('No user found for ID {}'.format(user_id))
        ID_TO_NAME[user_id] = users[0]['full_name']
        return users[0]['full_name']
示例#6
0
.define allows you to add commands which contains text.
They can be accessed via ~<command_name>, and will output what you put in.

.define code <text> will format the input as code.
'''


from tinydb import Query
from formatting import *
from utils import new_database


__author__ = 'alexkraak'
COMMAND = 'define'
CMD_DB = new_database('quote')
CMD = Query()
LIMIT = 20
ANGRY_STRING = 'please use in form .define <command_name> <command text>'
BAD_MEME_STRING = 'cannot use this image!'


def try_define_image(bot, thread_id, thread_type, text):
    if ' ' in text:
        command, image_url = text.split(' ', 1)
        try:
            bot.sendRemoteImage(
                image_url, thread_id=thread_id, thread_type=thread_type)
            text = None
        except Exception:
            bot.sendMessage(BAD_MEME_STRING,
示例#7
0
from requests_futures.sessions import FuturesSession
from paths import CONFIG
from tinydb import Query
from utils import new_database
import requests


COMMAND = 'np'
USERDB = new_database('lastfm')
USER = Query()
SESSION = FuturesSession(max_workers=100)
API_BASE = "http://ws.audioscrobbler.com/2.0/"
COLLAGE_BASE = "http://www.tapmusic.net/collage.php/"
SHORTENER_BASE = 'https://www.googleapis.com/urlshortener/v1/url'
PERIODS = ("7day", "1month", "3month", "6month", "12month", "overall")
REQUEST_PARAMETERS = {'api_key': CONFIG.LASTFM_API_KEY,
                      'format': 'json'}


def get_lastfm_request(method, **kwargs):
    ''' make a normal python request to the last.fm api
        return a Response() '''
    return requests.get(API_BASE, params={"method": method,
                                          **REQUEST_PARAMETERS,
                                          **kwargs})


def get_lastfm_asyncrequest(method, **kwargs):
    ''' make an aysnc request using a requests_futures FuturesSession
        to the last.fm api
        return a Future() '''
示例#8
0
from datetime import datetime, timedelta
from formatting import *
from plugins import gex
from tinydb import Query, where
from tinydb.operations import increment
from utils import new_database
from paths import CONFIG
import json
import random
import requests
import tabulate

__author__ = 'CianLR'
COMMAND = "linden"
USERDB = new_database('linden')
USER = Query()
REED_ID = None


class AlphaVantageTickerFetcher:
    def __init__(self):
        self.base_url = "https://www.alphavantage.co/query"
        self.params = ("?function=TIME_SERIES_INTRADAY"
                       "&symbol={}&interval=1min&apikey={}")

    def GetMultiple(self, tickers):
        return [self.GetSingle(t) for t in tickers]

    def GetSingle(self, ticker):
        url = self.base_url + self.params.format(ticker,
示例#9
0
 def __init__(self, user_db_path, thread_db_path):
     self.user_db = new_database(user_db_path)
     self.thread_db = new_database(thread_db_path)
示例#10
0
def plugin_setup():
    global USERDB, rss
    import feedparser
    rss = feedparser

    USERDB = new_database('letterboxd')
示例#11
0
def setup_database():
    global DATABASE
    DATABASE = new_database('intern')