@@ -1021,6 +1021,64 @@ async def update(self, ctx):
1021
1021
else :
1022
1022
return await ctx .send ('This command is disabled as the user have not starred <https://github.com/verixx/selfbot.py>' )
1023
1023
1024
+ @commands .command (pass_context = True )
1025
+ async def rpoll (self , ctx , * , args ):
1026
+ """Create a poll using reactions. {p}help rpoll for more information.
1027
+ {p}rpoll <question> | <answer> | <answer> - Create a poll. You may use as many answers as you want, placing a pipe | symbol in between them.
1028
+ Example:
1029
+ {p}rpoll What is your favorite anime? | Steins;Gate | Naruto | Attack on Titan | Shrek
1030
+ You can also use the "time" flag to set the amount of time in seconds the poll will last for.
1031
+ Example:
1032
+ {p}rpoll What time is it? | HAMMER TIME! | SHOWTIME! | time=10
1033
+ """
1034
+ await ctx .message .delete ()
1035
+ options = args .split (" | " )
1036
+ time = [x for x in options if x .startswith ("time=" )]
1037
+ if time :
1038
+ time = time [0 ]
1039
+ if time :
1040
+ options .remove (time )
1041
+ if len (options ) <= 1 :
1042
+ raise commands .errors .MissingRequiredArgument
1043
+ if len (options ) >= 11 :
1044
+ return await ctx .send (self .bot .bot_prefix + "You must have 9 options or less." )
1045
+ if time :
1046
+ time = int (time .strip ("time=" ))
1047
+ else :
1048
+ time = 30
1049
+ emoji = ['1⃣' , '2⃣' , '3⃣' , '4⃣' , '5⃣' , '6⃣' , '7⃣' , '8⃣' , '9⃣' ]
1050
+ to_react = []
1051
+ confirmation_msg = "**{}?**:\n \n " .format (options [0 ].rstrip ("?" ))
1052
+ for idx , option in enumerate (options [1 :]):
1053
+ confirmation_msg += "{} - {}\n " .format (emoji [idx ], option )
1054
+ to_react .append (emoji [idx ])
1055
+ confirmation_msg += "\n \n You have {} seconds to vote!" .format (time )
1056
+ poll_msg = await ctx .send (confirmation_msg )
1057
+ for emote in to_react :
1058
+ await poll_msg .add_reaction (emote )
1059
+ await asyncio .sleep (time )
1060
+ async for message in ctx .message .channel .history ():
1061
+ if message .id == poll_msg .id :
1062
+ poll_msg = message
1063
+ results = {}
1064
+ for reaction in poll_msg .reactions :
1065
+ if reaction .emoji in to_react :
1066
+ results [reaction .emoji ] = reaction .count - 1
1067
+ end_msg = "The poll is over. The results:\n \n "
1068
+ for result in results :
1069
+ end_msg += "{} {} - {} votes\n " .format (result , options [emoji .index (result )+ 1 ], results [result ])
1070
+ top_result = max (results , key = lambda key : results [key ])
1071
+ if len ([x for x in results if results [x ] == results [top_result ]]) > 1 :
1072
+ top_results = []
1073
+ for key , value in results .items ():
1074
+ if value == results [top_result ]:
1075
+ top_results .append (options [emoji .index (key )+ 1 ])
1076
+ end_msg += "\n The victory is tied between: {}" .format (", " .join (top_results ))
1077
+ else :
1078
+ top_result = options [emoji .index (top_result )+ 1 ]
1079
+ end_msg += "\n {} is the winner!" .format (top_result )
1080
+ await ctx .send (end_msg )
1081
+
1024
1082
@commands .command ()
1025
1083
async def cc (self , ctx , option , name = 'None' , content = None ):
1026
1084
git = self .bot .get_cog ('Git' )
0 commit comments