本文整理汇总了Python中pajbot.managers.HandlerManager类的典型用法代码示例。如果您正苦于以下问题:Python HandlerManager类的具体用法?Python HandlerManager怎么用?Python HandlerManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HandlerManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: award_tokens
def award_tokens(self, tokens, redis=None, force=False):
""" Returns True if tokens were awarded properly.
Returns False if not.
Tokens can only be rewarded once per stream ID.
"""
streamer = StreamHelper.get_streamer()
stream_id = StreamHelper.get_current_stream_id()
if stream_id is False:
return False
if redis is None:
redis = RedisManager.get()
key = '{streamer}:{username}:tokens'.format(
streamer=streamer, username=self.username)
if force:
res = True
redis.hset(key, stream_id, tokens)
else:
res = True if redis.hsetnx(key, stream_id, tokens) == 1 else False
if res is True:
HandlerManager.trigger('on_user_gain_tokens', self, tokens)
return res
开发者ID:TalVivian,项目名称:pajbot,代码行数:26,代码来源:user.py
示例2: command_start
def command_start(self, **options):
bot = options['bot']
source = options['source']
message = options['message']
if self.trivia_running:
bot.me('{}, a trivia is already running'.format(source.username_raw))
return
self.trivia_running = True
self.job.resume()
try:
self.point_bounty = int(message)
if self.point_bounty < 0:
self.point_bounty = 0
elif self.point_bounty > 50:
self.point_bounty = 50
except:
self.point_bounty = self.settings['default_point_bounty']
if self.point_bounty > 0:
bot.me('The trivia has started! {} points for each right answer!'.format(self.point_bounty))
else:
bot.me('The trivia has started!')
HandlerManager.add_handler('on_message', self.on_message)
开发者ID:TalVivian,项目名称:pajbot,代码行数:27,代码来源:trivia.py
示例3: stop_quest
def stop_quest(self):
HandlerManager.remove_handler('on_message', self.on_message)
redis = RedisManager.get()
self.reset_progress(redis=redis)
redis.delete(self.current_emote_key)
开发者ID:Nacht123,项目名称:pajbot,代码行数:7,代码来源:typeemote.py
示例4: create_stream
def create_stream(self, status):
log.info('Attempting to create a stream!')
with DBManager.create_session_scope(expire_on_commit=False) as db_session:
stream_chunk = db_session.query(StreamChunk).filter_by(broadcast_id=status['broadcast_id']).one_or_none()
new_stream = False
if stream_chunk is not None:
stream = stream_chunk.stream
else:
log.info('checking if there is an active stream already')
stream = db_session.query(Stream).filter_by(ended=False).order_by(Stream.stream_start.desc()).first()
new_stream = stream is None
if new_stream:
log.info('No active stream, create new!')
stream = Stream(status['created_at'],
title=status['title'])
db_session.add(stream)
db_session.commit()
log.info('Successfully added stream!')
stream_chunk = StreamChunk(stream, status['broadcast_id'], status['created_at'])
db_session.add(stream_chunk)
db_session.commit()
stream.stream_chunks.append(stream_chunk)
log.info('Created stream chunk')
self.current_stream = stream
self.current_stream_chunk = stream_chunk
db_session.expunge_all()
if new_stream:
HandlerManager.trigger('on_stream_start', stop_on_false=False)
log.info('Successfully created a stream')
开发者ID:Nacht123,项目名称:pajbot,代码行数:33,代码来源:stream.py
示例5: start_quest
def start_quest(self):
HandlerManager.add_handler('on_message', self.on_message)
redis = RedisManager.get()
self.load_progress(redis=redis)
self.load_data(redis=redis)
开发者ID:Nacht123,项目名称:pajbot,代码行数:7,代码来源:typeemote.py
示例6: stop_quest
def stop_quest(self):
HandlerManager.remove_handler('on_duel_complete', self.on_duel_complete)
redis = RedisManager.get()
self.reset_progress(redis=redis)
redis.delete(self.points_required_key)
开发者ID:Nacht123,项目名称:pajbot,代码行数:7,代码来源:winduelpoints.py
示例7: enable
def enable(self, bot):
self.bot = bot
HandlerManager.add_handler('on_message', self.on_message, priority=100)
HandlerManager.add_handler('on_commit', self.on_commit)
if bot:
self.run_later = bot.execute_delayed
if 'safebrowsingapi' in bot.config['main']:
# XXX: This should be loaded as a setting instead.
# There needs to be a setting for settings to have them as "passwords"
# so they're not displayed openly
self.safeBrowsingAPI = SafeBrowsingAPI(bot.config['main']['safebrowsingapi'], bot.nickname, bot.version)
else:
self.safeBrowsingAPI = None
if self.db_session is not None:
self.db_session.commit()
self.db_session.close()
self.db_session = None
self.db_session = DBManager.create_session()
self.blacklisted_links = []
for link in self.db_session.query(BlacklistedLink):
self.blacklisted_links.append(link)
self.whitelisted_links = []
for link in self.db_session.query(WhitelistedLink):
self.whitelisted_links.append(link)
开发者ID:Nacht123,项目名称:pajbot,代码行数:27,代码来源:linkchecker.py
示例8: commit_all
def commit_all(self):
log.info('Commiting all...')
for key, manager in self.commitable.items():
log.info('Commiting {0}'.format(key))
manager.commit()
log.info('Done with {0}'.format(key))
log.info('ok!')
HandlerManager.trigger('on_commit', stop_on_false=False)
开发者ID:Nacht123,项目名称:pajbot,代码行数:9,代码来源:bot.py
示例9: disable
def disable(self, bot):
HandlerManager.remove_handler('on_message', self.on_message)
HandlerManager.remove_handler('on_commit', self.on_commit)
if self.db_session is not None:
self.db_session.commit()
self.db_session.close()
self.db_session = None
self.links = {}
开发者ID:Nacht123,项目名称:pajbot,代码行数:9,代码来源:linktracker.py
示例10: start_quest
def start_quest(self):
HandlerManager.add_handler('on_duel_complete', self.on_duel_complete)
redis = RedisManager.get()
self.load_progress(redis=redis)
self.load_data(redis=redis)
self.LIMIT = self.points_required
开发者ID:Nacht123,项目名称:pajbot,代码行数:9,代码来源:winduelpoints.py
示例11: base_paid_timeout
def base_paid_timeout(self, bot, source, message, _time, _cost):
if message is None or len(message) == 0:
return False
username = message.split(' ')[0]
if len(username) < 2:
return False
with bot.users.find_context(username) as victim:
if victim is None:
bot.whisper(source.username, 'This user does not exist FailFish')
return False
if victim.last_active is None or (datetime.datetime.now() - victim._last_active).total_seconds() > 10 * 60:
bot.whisper(source.username, 'This user has not been active in chat within the last 10 minutes.')
return False
"""
if victim == source:
bot.whisper(source.username, 'You can\'t timeout yourself FailFish')
return False
"""
if victim.moderator is True:
bot.whisper(source.username, 'This person has mod privileges, timeouting this person is not worth it.')
return False
if victim.level >= self.settings['bypass_level']:
bot.whisper(source.username, 'This person\'s user level is too high, you can\'t timeout this person.')
return False
now = datetime.datetime.now()
if victim.timed_out is True and victim.timeout_end > now:
victim.timeout_end += datetime.timedelta(seconds=_time)
bot.whisper(victim.username, '{victim.username}, you were timed out for an additional {time} seconds by {source.username}'.format(
victim=victim,
source=source,
time=_time))
bot.whisper(source.username, 'You just used {0} points to time out {1} for an additional {2} seconds.'.format(_cost, username, _time))
num_seconds = int((victim.timeout_end - now).total_seconds())
bot._timeout(username, num_seconds)
else:
bot.whisper(source.username, 'You just used {0} points to time out {1} for {2} seconds.'.format(_cost, username, _time))
bot.whisper(username, '{0} just timed you out for {1} seconds. /w {2} !$unbanme to unban yourself for points forsenMoney'.format(source.username, _time, bot.nickname))
bot._timeout(username, _time)
victim.timed_out = True
victim.timeout_start = now
victim.timeout_end = now + datetime.timedelta(seconds=_time)
if self.settings['show_on_clr']:
payload = {'user': source.username, 'victim': victim.username}
bot.websocket_manager.emit('timeout', payload)
HandlerManager.trigger('on_paid_timeout',
source, victim, _cost,
stop_on_false=False)
开发者ID:Nacht123,项目名称:pajbot,代码行数:56,代码来源:paidtimeout.py
示例12: enable
def enable(self, bot):
HandlerManager.add_handler('on_message', self.on_message, priority=200)
HandlerManager.add_handler('on_commit', self.on_commit)
if self.db_session is not None:
self.db_session.commit()
self.db_session.close()
self.db_session = None
self.links = {}
self.db_session = DBManager.create_session()
开发者ID:Nacht123,项目名称:pajbot,代码行数:10,代码来源:linktracker.py
示例13: on_message
def on_message(self, source, msg_raw, message_emotes, whisper, urls, event):
if len(message_emotes) > 0:
if hasattr(self, 'bingo_running') and self.bingo_running is True:
if len(message_emotes) == 1 and len(msg_raw.split(' ')) == 1:
if message_emotes[0]['code'] == self.bingo_target:
HandlerManager.trigger('on_bingo_win', source, self.bingo_points, self.bingo_target)
self.bingo_running = False
self.bingo_bttv_twitch_running = False
self.bot.me('{0} won the bingo! {1} was the target. Congrats, {2} points to you PogChamp'.format(source.username_raw, self.bingo_target, self.bingo_points))
source.points += self.bingo_points
log.info('{0} won the bingo for {1} points!'.format(source.username_raw, self.bingo_points))
开发者ID:Nacht123,项目名称:pajbot,代码行数:11,代码来源:bingo.py
示例14: accept_duel
def accept_duel(self, **options):
"""
Accepts any active duel requests you've received.
How to add: !add funccommand accept accept_duel --cd 0 --usercd 0
How to use: !accept
"""
bot = options['bot']
source = options['source']
init_dueling_variables(source)
duel_tax = 0.3 # 30% tax
if source.duel_request is not False:
if not source.can_afford(source.duel_price) or not source.duel_request.can_afford(source.duel_price):
bot.whisper(source.username, 'Your duel request with {} was cancelled due to one of you not having enough points.'.format(source.duel_request.username_raw))
bot.whisper(source.duel_request.username, 'Your duel request with {} was cancelled due to one of you not having enough points.'.format(source.username_raw))
source.duel_request.duel_target = False
source.duel_request = False
return False
source.points -= source.duel_price
source.duel_request.points -= source.duel_price
winning_pot = int(source.duel_price * (1.0 - duel_tax))
participants = [source, source.duel_request]
winner = random.choice(participants)
participants.remove(winner)
loser = participants.pop()
winner.points += source.duel_price
winner.points += winning_pot
bot.duel_manager.user_won(winner, winning_pot)
bot.duel_manager.user_lost(loser, source.duel_price)
arguments = {
'winner': winner.username,
'loser': loser.username,
'total_pot': source.duel_price,
'extra_points': winning_pot,
}
if source.duel_price > 0:
message = self.get_phrase('message_won_points', **arguments)
if source.duel_price >= 500:
bot.websocket_manager.emit('notification', {'message': '{} won the duel vs {}'.format(winner.username_raw, loser.username_raw)})
else:
message = self.get_phrase('message_won', **arguments)
bot.say(message)
source.duel_request.duel_target = False
source.duel_request = False
source.duel_price = 0
HandlerManager.trigger('on_duel_complete',
winner, loser,
winning_pot, source.duel_price)
开发者ID:TalVivian,项目名称:pajbot,代码行数:54,代码来源:duel.py
示例15: command_stop
def command_stop(self, **options):
bot = options['bot']
source = options['source']
if not self.trivia_running:
bot.me('{}, no trivia is active right now'.format(source.username_raw))
return
self.job.pause()
self.trivia_running = False
self.step_end()
bot.me('The trivia has been stopped.')
HandlerManager.remove_handler('on_message', self.on_message)
开发者ID:TalVivian,项目名称:pajbot,代码行数:15,代码来源:trivia.py
示例16: parse_message
def parse_message(self, msg_raw, source, event, tags={}, whisper=False):
msg_lower = msg_raw.lower()
emote_tag = None
for tag in tags:
if tag['key'] == 'subscriber' and event.target == self.channel:
source.subscriber = tag['value'] == '1'
elif tag['key'] == 'emotes' and tag['value']:
emote_tag = tag['value']
elif tag['key'] == 'display-name' and tag['value']:
source.username_raw = tag['value']
elif tag['key'] == 'user-type':
source.moderator = tag['value'] == 'mod' or source.username == self.streamer
# source.num_lines += 1
if source is None:
log.error('No valid user passed to parse_message')
return False
if source.banned:
self.ban(source.username)
return False
# If a user types when timed out, we assume he's been unbanned for a good reason and remove his flag.
if source.timed_out is True:
source.timed_out = False
# Parse emotes in the message
message_emotes = self.emotes.parse_message_twitch_emotes(source, msg_raw, emote_tag, whisper)
urls = self.find_unique_urls(msg_raw)
# log.debug('{2}{0}: {1}'.format(source.username, msg_raw, '<w>' if whisper else ''))
res = HandlerManager.trigger('on_message',
source, msg_raw, message_emotes, whisper, urls, event,
stop_on_false=True)
if res is False:
return False
source.last_seen = datetime.datetime.now()
source.last_active = datetime.datetime.now()
if source.ignored:
return False
if msg_lower[:1] == '!':
msg_lower_parts = msg_lower.split(' ')
trigger = msg_lower_parts[0][1:]
msg_raw_parts = msg_raw.split(' ')
remaining_message = ' '.join(msg_raw_parts[1:]) if len(msg_raw_parts) > 1 else None
if trigger in self.commands:
command = self.commands[trigger]
extra_args = {
'emotes': message_emotes,
'trigger': trigger,
}
command.run(self, source, remaining_message, event=event, args=extra_args, whisper=whisper)
开发者ID:Nacht123,项目名称:pajbot,代码行数:60,代码来源:bot.py
示例17: go_offline
def go_offline(self):
with DBManager.create_session_scope(expire_on_commit=False) as db_session:
self.current_stream.ended = True
self.current_stream.stream_end = self.first_offline
self.current_stream_chunk.chunk_end = self.first_offline
db_session.add(self.current_stream)
db_session.add(self.current_stream_chunk)
db_session.commit()
db_session.expunge_all()
self.last_stream = self.current_stream
self.current_stream = None
self.current_stream_chunk = None
HandlerManager.trigger('on_stream_stop', stop_on_false=False)
开发者ID:Nacht123,项目名称:pajbot,代码行数:18,代码来源:stream.py
示例18: end_raffle
def end_raffle(self):
if not self.raffle_running:
return False
self.raffle_running = False
if len(self.raffle_users) == 0:
self.bot.me('Wow, no one joined the raffle DansGame')
return False
winner = random.choice(self.raffle_users)
self.raffle_users = []
self.bot.websocket_manager.emit('notification', {'message': '{} won {} points in the raffle!'.format(winner.username_raw, self.raffle_points)})
self.bot.me('The raffle has finished! {0} won {1} points! PogChamp'.format(winner.username_raw, self.raffle_points))
winner.points += self.raffle_points
HandlerManager.trigger('on_raffle_win', winner, self.raffle_points)
开发者ID:TalVivian,项目名称:pajbot,代码行数:20,代码来源:raffle.py
示例19: on_pubmsg
def on_pubmsg(self, chatconn, event):
if event.source.user == self.nickname:
return False
# We use .lower() in case twitch ever starts sending non-lowercased usernames
source = self.users[event.source.user.lower()]
res = HandlerManager.trigger('on_pubmsg',
source, event.arguments[0],
stop_on_false=True)
if res is False:
return False
self.parse_message(event.arguments[0], source, event, tags=event.tags)
开发者ID:TalVivian,项目名称:pajbot,代码行数:14,代码来源:bot.py
示例20: disable
def disable(self, bot):
HandlerManager.remove_handler('on_user_sub', self.on_user_sub)
HandlerManager.remove_handler('on_user_resub', self.on_user_resub)
开发者ID:Nacht123,项目名称:pajbot,代码行数:3,代码来源:raffle.py
注:本文中的pajbot.managers.HandlerManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论