本文整理匯總了Python中Core.Util.UtilBot.get_vote_status方法的典型用法代碼示例。如果您正苦於以下問題:Python UtilBot.get_vote_status方法的具體用法?Python UtilBot.get_vote_status怎麽用?Python UtilBot.get_vote_status使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Core.Util.UtilBot
的用法示例。
在下文中一共展示了UtilBot.get_vote_status方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: vote
# 需要導入模塊: from Core.Util import UtilBot [as 別名]
# 或者: from Core.Util.UtilBot import get_vote_status [as 別名]
#.........這裏部分代碼省略.........
# Abstains user from voting.
if set_vote is not None and set_vote.lower() == 'abstain':
if UtilBot.is_vote_started(event.conv_id):
bot.send_message(event.conv, 'User {} has abstained from voting.'.format(event.user.full_name))
if UtilBot.abstain_voter(event.conv_id, event.user.full_name):
bot.send_message(event.conv, "The vote has ended because all voters have abstained.")
return
else:
bot.send_message(event.conv, 'No vote currently in process to abstain from.')
return
# Check if the vote has ended
vote_result = UtilBot.check_if_vote_finished(event.conv_id)
if vote_result is not None:
if vote_result != 0:
bot.send_message(event.conv,
'In the matter of: "' + UtilBot.get_vote_subject(event.conv_id) + '", the ' + (
'Yeas' if vote_result > 0 else 'Nays') + ' have it.')
else:
bot.send_message(event.conv, "The vote ended in a tie in the matter of: {}".format(
UtilBot.get_vote_subject(event.conv_id)))
UtilBot.end_vote(event.conv_id)
return
# Cancels the vote
if set_vote is not None and set_vote.lower() == "cancel":
if UtilBot.is_vote_started(event.conv_id):
bot.send_message(event.conv, 'Vote "{}" cancelled.'.format(UtilBot.get_vote_subject(event.conv_id)))
UtilBot.end_vote(event.conv_id)
else:
bot.send_message(event.conv, 'No vote currently started.')
return
# Starts a new vote
if not UtilBot.is_vote_started(event.conv_id) and set_vote == "start":
vote_subject = ' '.join(args)
vote_callback = None
# TODO Refactor this into a more easily extensible system.
if vote_subject.lower().strip() == "admin": # For the special Conversation Admin case.
vote_subject = '{} for Conversation Admin for chat {}'.format(event.user.full_name,
get_conv_name(event.conv))
def set_conv_admin(won):
if won:
try:
bot.config["conversations"][event.conv_id]["conversation_admin"] = event.user.id_[0]
except (KeyError, TypeError):
bot.config["conversations"][event.conv_id] = {}
bot.config["conversations"][event.conv_id]["admin"] = event.user.id_[0]
bot.config.save()
vote_callback = set_conv_admin
UtilBot.set_vote_subject(event.conv_id, vote_subject)
UtilBot.init_new_vote(event.conv_id, event.conv.users)
if vote_callback is not None:
UtilBot.set_vote_callback(event.conv_id, vote_callback)
bot.send_message(event.conv, "Vote started for subject: " + vote_subject)
return
# Cast a vote.
if set_vote is not None and UtilBot.is_vote_started(event.conv_id):
if UtilBot.can_user_vote(event.conv_id, event.user):
set_vote = set_vote.lower()
if set_vote == "true" or set_vote == "yes" or set_vote == "yea" or set_vote == "for" or set_vote == "yay" or set_vote == "aye":
UtilBot.set_vote(event.conv_id, event.user.full_name, True)
elif set_vote == "false" or set_vote == "no" or set_vote == "nay" or set_vote == "against":
UtilBot.set_vote(event.conv_id, event.user.full_name, False)
else:
bot.send_message(event.conv,
"{}, you did not enter a valid vote parameter.".format(event.user.full_name))
return
# Check if the vote has ended
vote_result = UtilBot.check_if_vote_finished(event.conv_id)
if vote_result is not None:
if vote_result != 0:
bot.send_message(event.conv,
'In the matter of: "' + UtilBot.get_vote_subject(event.conv_id) + '", the ' + (
'Yeas' if vote_result > 0 else 'Nays') + ' have it.')
else:
bot.send_message(event.conv, "The vote ended in a tie in the matter of: {}".format(
UtilBot.get_vote_subject(event.conv_id)))
UtilBot.end_vote(event.conv_id, vote_result)
return
else:
bot.send_message(event.conv_id, 'User {} is not allowed to vote.'.format(event.user.full_name))
return
# Check the status of a vote.
if UtilBot.is_vote_started(event.conv_id):
status = UtilBot.get_vote_status(event.conv_id)
if len(status) > 1:
bot.send_message_segments(event.conv, UtilBot.text_to_segments('\n'.join(status)))
else:
bot.send_message(event.conv, "No vote currently started.")
else:
bot.send_message(event.conv, "No vote currently started.")