def __init__(self, updater: Updater):
super().__init__(updater)
self.commands_handlers = [
CommandHandler('add', self.command_add, pass_args=True),
CommandHandler('remove', self.command_remove, pass_args=True),
CommandHandler('show', self.command_list),
]
self.store = RedditStore('reddit',
url=REDIS_URL,
clear_age=RedditSetup.db_clear_age)
self.pipe = RedditPipe(self.name, self.updater, self.store)
python类Updater()的实例源码
def __init__(self, channel_id: str, updater: Updater):
self.logger = logging.getLogger(self.__class__.__name__)
self.channel_id = channel_id
self.updater = updater
self.scheduler = Scheduler(self.updater.job_queue)
self.post_interval = 60
def __init__(self, updater: Updater):
"""
- name: name of channel in telegram. **Must** starts with "@".
- label: identifier for channel. **Must** be unique.
- pipe_classes:
- commands_handlers: list of command handlers which would be attached when we need them and detached when we don't.
:param updater: bot updater.
"""
self.label = self.__class__.__name__
self.updater = updater
self.dispatcher = updater.dispatcher
self.commands_handlers = []
def __init__(self, channel_id: str, updater: Updater):
self.channel_id = channel_id
self.bot = updater.bot
self.logger = logging.getLogger(self.__class__.__name__)
def __init__(self, token: str):
self.token = token
self.logger = logging.getLogger(self.__class__.__name__)
self.updater = Updater(token)
self.dispatcher = self.updater.dispatcher
self.chosen_channel = None
self.admins = None
def __init__(self, token):
self._telegram = Updater(token)
self._token = token
self._bot = None
def set_up(self, updater: Updater):
self.updater = updater
self.dispatcher = updater.dispatcher
active_user_filter = ActiveUsersFilter(self.active_users)
for handler in self.commands_handlers:
handler.filters = active_user_filter
def set_up(self, channel_id: str, updater: Updater, **kwargs):
self.channel_id = channel_id
self.updater = updater
self.scheduler = Scheduler(self.updater.job_queue)
def __init__(self, token: str, admins=None):
self.logger = logging.getLogger(self.__class__.__name__)
self.token = token
self.updater = Updater(token)
self.dispatcher = self.updater.dispatcher
self.channels = {}
self.chosen_channels = {}
self.admins = admins
def __init__(self, channel_id: str, updater: Updater):
self.logger = logging.getLogger(self.__class__.__name__)
self.channel_id = channel_id
self.bot = updater.bot
def set_up(self, channel_id: str, updater: Updater, **kwargs):
store: ImgurStore = kwargs['store']
settings: ImgurSettings = kwargs['settings']
super(ImgurPipe, self).set_up(channel_id, updater)
self.store = store
self.settings = settings
def set_up(self, channel_id: str, updater: Updater, **kwargs):
store: RedditStore = kwargs['store']
settings: RedditSettings = kwargs['settings']
self.store = store
self.settings = settings
super(RedditPipe, self).set_up(channel_id, updater)
def __init__(self, channel_id: str, updater: Updater, store: RedditStore):
super().__init__(channel_id, updater)
self.store = store
self.timeout = 60 # seconds
def main():
u = Updater('YOUR-TOKEN')
dp = u.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(MessageHandler(Filters.text, music))
u.start_polling()
u.idle()
def __init__(self):
self.updater = Updater(token=settings.TELEGRAM_TOKEN)
self.dispatcher = self.updater.dispatcher
telegram_manager.py 文件源码
项目:Cryptocurrencies-arbitrage-algorithm
作者: coupetmaxence
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater("386765167:AAEAeiO5sgg5AjlQFIw6OiYWTXr1qBeQsrE")
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("begin_simple_arbitrage", begin_simple_arbitrage))
dp.add_handler(CommandHandler("stop_simple_arbitrage", stop_simple_arbitrage))
# on noncommand i.e message - echo the message on Telegram
dp.add_handler(MessageHandler(Filters.text, non_command))
#Start scheduler
t1 = Thread(target=ThreadFunctionScheduler, args=(updater.bot,))
t1.start()
# Start the Bot
t2 = Thread(target=ThreadBot, args=(updater,))
t2.start()
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
def run(self):
global_vars.create_variable('mdb', MessageDB('message.db'))
qq_bot = CQHttp(api_root=API_ROOT,
access_token=ACCESS_TOKEN,
secret=SECRET)
global_vars.create_variable('callback_queue', queue.Queue())
global_vars.qq_bot = qq_bot
global_vars.tg_bot_id = int(TOKEN.split(':')[0])
updater = Updater(TOKEN)
global_vars.create_variable('job_queue', updater.job_queue)
global_vars.tg_bot = updater.bot
# Get the dispatcher to register handlers
dp = updater.dispatcher
global_vars.dp = dp
dp.add_error_handler(error)
updater.start_polling(poll_interval=1.0, timeout=200)
threaded_server = threading.Thread(
target=qq_bot.run,
kwargs=dict(host=HOST, port=PORT),
daemon=True)
threaded_server.start()
import plugins # load all plugins
while True:
utils.from_main_thread_blocking()
time.sleep(1)
# Block until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
def main():
token = os.environ['TELEGRAMBOT']
updater = Updater(token)
dp = updater.dispatcher
#Filling data structures.
disim_news.preparing_disim()
univaq_news.preparing_univaq()
disim_prof.preparing_prof()
updater.job_queue.run_repeating(disim_news.check_disim_news, 150)
updater.job_queue.run_repeating(univaq_news.check_univaq_news, 150)
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
dp.add_handler(CommandHandler("disim", disim_news.show_disim_news, pass_args=True))
dp.add_handler(CommandHandler("disimon", disim_news.disimon))
dp.add_handler(CommandHandler("disimoff", disim_news.disimoff))
dp.add_handler(CommandHandler("evidenza", univaq_news.evidenza))
dp.add_handler(CommandHandler("ultimissime", univaq_news.ultimissime))
dp.add_handler(CommandHandler("univaqon", univaq_news.univaqon))
dp.add_handler(CommandHandler("univaqoff", univaq_news.univaqoff))
dp.add_handler(CommandHandler("prof", disim_prof.prof))
dp.add_handler(CommandHandler("segreteria", disim_secretary.secretary))
dp.add_handler(CommandHandler("mensa", univaq_general.canteen))
dp.add_handler(CommandHandler("adsu", univaq_general.adsu))
dp.add_handler(CommandHandler("feedback", administrator_commands.feedback))
dp.add_handler(CommandHandler("send", administrator_commands.send, pass_args=True))
dp.add_handler(CommandHandler("notify", administrator_commands.notify, pass_args=True))
updater.start_polling()
updater.idle()
def init(config: dict) -> None:
"""
Initializes this module with the given config,
registers all known command handlers
and starts polling for message updates
:param config: config to use
:return: None
"""
global _UPDATER
_CONF.update(config)
if not is_enabled():
return
_UPDATER = Updater(token=config['telegram']['token'], workers=0)
# Register command handler and start telegram message polling
handles = [
CommandHandler('status', _status),
CommandHandler('profit', _profit),
CommandHandler('balance', _balance),
CommandHandler('start', _start),
CommandHandler('stop', _stop),
CommandHandler('forcesell', _forcesell),
CommandHandler('performance', _performance),
CommandHandler('count', _count),
CommandHandler('help', _help),
CommandHandler('version', _version),
]
for handle in handles:
_UPDATER.dispatcher.add_handler(handle)
_UPDATER.start_polling(
clean=True,
bootstrap_retries=-1,
timeout=30,
read_latency=60,
)
logger.info(
'rpc.telegram is listening for following commands: %s',
[h.command for h in handles]
)
def send2Channel(messages=None):
updater = Updater(token=token)
bot = telegram.Bot(token=token)
jober = updater.job_queue
dispatcher = updater.dispatcher
bot.send_message(channel,str(messages))