2018-10-13 19:48:42 -07:00
import asyncio
import datetime
2020-10-05 00:18:57 +04:00
from typing import Literal , Optional
2020-08-26 17:57:43 +01:00
2018-10-13 19:48:42 -07:00
import discord
import random
2019-10-08 03:21:00 +02:00
import math
2018-10-13 19:48:42 -07:00
from redbot . core import commands , checks , Config , bank
2020-01-09 16:57:33 -08:00
from redbot . core . utils . chat_formatting import box , pagify , humanize_number
2018-10-13 19:48:42 -07:00
from redbot . core . utils . menus import menu , DEFAULT_CONTROLS
2022-10-06 22:42:10 +01:00
__version__ = " 0.1.7 "
2019-10-11 03:36:15 +02:00
2019-05-22 17:06:40 +02:00
2019-10-02 08:17:56 -07:00
class TrickOrTreat ( commands . Cog ) :
2020-09-06 23:57:03 -07:00
""" Trick or treating for your server. """
2020-08-26 17:57:43 +01:00
async def red_delete_data_for_user (
2020-10-05 07:51:10 -07:00
self ,
* ,
requester : Literal [ " discord " , " owner " , " user " , " user_strict " ] ,
user_id : int ,
2020-08-26 17:57:43 +01:00
) :
await self . config . user_from_id ( user_id ) . clear ( )
2018-10-13 19:48:42 -07:00
def __init__ ( self , bot ) :
self . bot = bot
self . config = Config . get_conf ( self , 2710311393 , force_registration = True )
default_guild = { " cooldown " : 300 , " channel " : [ ] , " pick " : 50 , " toggle " : False }
default_user = {
" candies " : 0 ,
2020-10-05 07:51:10 -07:00
" chocolate " : 0 ,
2022-10-06 22:42:10 +01:00
" cookies " : 0 ,
2018-10-13 19:48:42 -07:00
" eaten " : 0 ,
" last_tot " : " 2018-01-01 00:00:00.000001 " ,
" lollipops " : 0 ,
" sickness " : 0 ,
" stars " : 0 ,
}
self . config . register_user ( * * default_user )
self . config . register_guild ( * * default_guild )
@commands.guild_only ( )
2020-10-05 07:55:17 -07:00
@commands.cooldown ( 1 , 1 , commands . BucketType . user )
2018-10-13 19:48:42 -07:00
@commands.command ( )
2020-10-05 00:18:57 +04:00
async def eatcandy ( self , ctx , number : Optional [ int ] = 1 , candy_type = None ) :
2018-10-13 19:48:42 -07:00
""" Eat some candy.
2020-10-05 07:51:10 -07:00
2022-10-06 22:42:10 +01:00
Valid types : candy / candie ( s ) , chocolate ( s ) , lollipop ( s ) , cookie ( s ) , star ( s )
2020-10-05 07:51:10 -07:00
Examples :
` [ p ] eatcandy 3 lollipops `
` [ p ] eatcandy star `
\N { CANDY }
The star of this competition . You should try to eat all of these , but don ' t get too sick.
\N { CHOCOLATE BAR }
Reduces sickness by 10.
\N { LOLLIPOP }
Reduces sickness by 20.
2022-10-06 22:42:10 +01:00
\N { FORTUNE COOKIE }
Sets sickness to a random amount - fortune favours the brave .
2020-10-05 07:51:10 -07:00
\N { WHITE MEDIUM STAR }
Resets sickness to 0.
"""
2018-10-13 19:48:42 -07:00
userdata = await self . config . user ( ctx . author ) . all ( )
pick = await self . config . guild ( ctx . guild ) . pick ( )
if not candy_type :
candy_type = " candies "
2019-10-04 19:44:45 -06:00
if number < 0 :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( " That doesn ' t sound fun. " )
2019-10-04 19:44:45 -06:00
if number == 0 :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( " You pretend to eat a candy. " )
2018-10-13 19:48:42 -07:00
if candy_type in [ " candies " , " candy " ] :
candy_type = " candies "
if candy_type in [ " lollipops " , " lollipop " ] :
candy_type = " lollipops "
if candy_type in [ " stars " , " star " ] :
candy_type = " stars "
2020-10-05 07:51:10 -07:00
if candy_type in [ " chocolate " , " chocolates " ] :
2022-10-06 20:08:17 -04:00
candy_type = " chocolate "
2022-10-06 22:42:10 +01:00
if candy_type in [ " cookie " , " cookies " ] :
candy_type = " cookies "
2022-10-06 20:08:17 -04:00
candy_list = [ " candies " , " chocolate " , " lollipops " , " cookies " , " stars " ]
2018-10-13 19:48:42 -07:00
if candy_type not in candy_list :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( " That ' s not a candy type! Use the inventory command to see what you have. " )
2018-10-13 19:48:42 -07:00
if userdata [ candy_type ] < number :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( f " You don ' t have that many { candy_type } . " )
2018-10-13 19:48:42 -07:00
if userdata [ candy_type ] == 0 :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( f " You contemplate the idea of eating { candy_type } . " )
2018-10-13 19:48:42 -07:00
eat_phrase = [
" You leisurely enjoy " ,
" You take the time to savor " ,
" You eat " ,
" You scarf down " ,
" You sigh in contentment after eating " ,
" You gobble up " ,
" You make a meal of " ,
" You devour " ,
2020-10-05 07:51:10 -07:00
" You monstrously pig out on " ,
" You hastily chomp down on " ,
" You daintily partake of " ,
" You earnestly consume " ,
2018-10-13 19:48:42 -07:00
]
if candy_type in [ " candies " , " candy " ] :
if ( userdata [ " sickness " ] + number * 2 ) in range ( 70 , 95 ) :
2021-09-28 11:13:05 -07:00
await ctx . reply ( " After all that candy, sugar doesn ' t sound so good. " )
2018-10-13 19:48:42 -07:00
yuck = random . randint ( 1 , 10 )
if yuck == 10 :
await self . config . user ( ctx . author ) . sickness . set ( userdata [ " sickness " ] + 25 )
if yuck in range ( 1 , 9 ) :
2020-08-26 17:57:43 +01:00
await self . config . user ( ctx . author ) . sickness . set ( userdata [ " sickness " ] + ( yuck * 2 ) )
2018-10-13 19:48:42 -07:00
if userdata [ " candies " ] > 3 + number :
lost_candy = userdata [ " candies " ] - random . randint ( 1 , 3 ) - number
else :
lost_candy = userdata [ " candies " ]
pick_now = await self . config . guild ( ctx . guild ) . pick ( )
if lost_candy < 0 :
await self . config . user ( ctx . author ) . candies . set ( 0 )
await self . config . guild ( ctx . guild ) . pick . set ( pick_now + lost_candy )
else :
2020-08-26 17:57:43 +01:00
await self . config . user ( ctx . author ) . candies . set ( userdata [ " candies " ] - lost_candy )
2018-10-13 19:48:42 -07:00
await self . config . guild ( ctx . guild ) . pick . set ( pick_now + lost_candy )
2020-08-26 17:57:43 +01:00
await self . config . user ( ctx . author ) . eaten . set ( userdata [ " eaten " ] + ( userdata [ " candies " ] - lost_candy ) )
2018-10-13 19:48:42 -07:00
2021-09-28 11:13:05 -07:00
return await ctx . reply (
2018-10-13 19:48:42 -07:00
f " You begin to think you don ' t need all this candy, maybe... \n * { lost_candy } candies are left behind* "
)
if ( userdata [ " sickness " ] + number ) > 96 :
await self . config . user ( ctx . author ) . sickness . set ( userdata [ " sickness " ] + 30 )
lost_candy = userdata [ " candies " ] - random . randint ( 1 , 5 )
2018-10-14 17:02:01 -07:00
if lost_candy < = 0 :
await self . config . user ( ctx . author ) . candies . set ( 0 )
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " ... " )
2018-10-17 15:37:12 -07:00
await asyncio . sleep ( 2 )
await message . edit ( content = " .......... " )
await asyncio . sleep ( 2 )
2018-10-14 17:02:01 -07:00
return await message . edit (
content = " You feel absolutely disgusted. At least you don ' t have any candies left. "
)
2018-10-13 19:48:42 -07:00
await self . config . guild ( ctx . guild ) . pick . set ( pick + lost_candy )
await self . config . user ( ctx . author ) . candies . set ( 0 )
2020-08-26 17:57:43 +01:00
await self . config . user ( ctx . author ) . eaten . set ( userdata [ " eaten " ] + ( userdata [ " candies " ] - lost_candy ) )
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " ... " )
2018-10-17 15:37:12 -07:00
await asyncio . sleep ( 2 )
await message . edit ( content = " .......... " )
await asyncio . sleep ( 2 )
2018-10-13 19:48:42 -07:00
return await message . edit (
content = f " You toss your candies on the ground in disgust. \n * { lost_candy } candies are left behind* "
)
pluralcandy = " candy " if number == 1 else " candies "
2021-09-28 11:13:05 -07:00
await ctx . reply (
2019-10-11 03:02:54 +02:00
f " { random . choice ( eat_phrase ) } { number } { pluralcandy } . (Total eaten: ` { humanize_number ( await self . config . user ( ctx . author ) . eaten ( ) + number ) } ` \N{CANDY} ) "
)
2018-10-13 19:48:42 -07:00
await self . config . user ( ctx . author ) . sickness . set ( userdata [ " sickness " ] + ( number * 2 ) )
await self . config . user ( ctx . author ) . candies . set ( userdata [ " candies " ] - number )
await self . config . user ( ctx . author ) . eaten . set ( userdata [ " eaten " ] + number )
2020-10-05 07:51:10 -07:00
if candy_type in [ " chocolates " , " chocolate " ] :
pluralchoc = " chocolate " if number == 1 else " chocolates "
2021-09-28 11:13:05 -07:00
await ctx . reply (
2020-10-05 07:51:10 -07:00
f " { random . choice ( eat_phrase ) } { number } { pluralchoc } . You feel slightly better! \n *Sickness has gone down by { number * 10 } * "
)
new_sickness = userdata [ " sickness " ] - ( number * 10 )
if new_sickness < 0 :
new_sickness = 0
await self . config . user ( ctx . author ) . sickness . set ( new_sickness )
await self . config . user ( ctx . author ) . chocolate . set ( userdata [ " chocolate " ] - number )
await self . config . user ( ctx . author ) . eaten . set ( userdata [ " eaten " ] + number )
2018-10-13 19:48:42 -07:00
if candy_type in [ " lollipops " , " lollipop " ] :
pluralpop = " lollipop " if number == 1 else " lollipops "
2021-09-28 11:13:05 -07:00
await ctx . reply (
2018-10-13 19:48:42 -07:00
f " { random . choice ( eat_phrase ) } { number } { pluralpop } . You feel slightly better! \n *Sickness has gone down by { number * 20 } * "
)
new_sickness = userdata [ " sickness " ] - ( number * 20 )
if new_sickness < 0 :
new_sickness = 0
await self . config . user ( ctx . author ) . sickness . set ( new_sickness )
await self . config . user ( ctx . author ) . lollipops . set ( userdata [ " lollipops " ] - number )
await self . config . user ( ctx . author ) . eaten . set ( userdata [ " eaten " ] + number )
2020-10-05 07:51:10 -07:00
2022-10-06 22:42:10 +01:00
if candy_type in [ " cookies " , " cookie " ] :
pluralcookie = " cookie " if number == 1 else " cookies "
new_sickness = random . randint ( 0 , 100 )
old_sickness = userdata [ " sickness " ]
if new_sickness > old_sickness :
phrase = f " You feel worse! \n *Sickness has gone up by { new_sickness - old_sickness } * "
else :
phrase = f " You feel better! \n *Sickness has gone down by { old_sickness - new_sickness } * "
await ctx . reply (
f " { random . choice ( eat_phrase ) } { number } { pluralcookie } . { phrase } "
)
await self . config . user ( ctx . author ) . sickness . set ( new_sickness )
await self . config . user ( ctx . author ) . cookies . set ( userdata [ " cookies " ] - number )
await self . config . user ( ctx . author ) . eaten . set ( userdata [ " eaten " ] + number )
2018-10-13 19:48:42 -07:00
if candy_type in [ " stars " , " star " ] :
pluralstar = " star " if number == 1 else " stars "
2021-09-28 11:13:05 -07:00
await ctx . reply (
2018-10-13 19:48:42 -07:00
f " { random . choice ( eat_phrase ) } { number } { pluralstar } . You feel great! \n *Sickness has been reset* "
)
await self . config . user ( ctx . author ) . sickness . set ( 0 )
await self . config . user ( ctx . author ) . stars . set ( userdata [ " stars " ] - number )
await self . config . user ( ctx . author ) . eaten . set ( userdata [ " eaten " ] + number )
@commands.guild_only ( )
@checks.mod_or_permissions ( administrator = True )
@commands.command ( )
2019-10-11 03:02:54 +02:00
async def totbalance ( self , ctx ) :
2021-09-27 09:50:07 -07:00
""" [Admin] Check how many candies are ' on the ground ' in the guild. """
2018-10-13 19:48:42 -07:00
pick = await self . config . guild ( ctx . guild ) . pick ( )
await ctx . send ( f " The guild is currently holding: { pick } \N{CANDY} " )
@commands.guild_only ( )
@commands.command ( )
2020-10-05 07:51:10 -07:00
async def buycandy ( self , ctx , pieces : int ) :
2018-10-13 19:48:42 -07:00
""" Buy some candy. Prices could vary at any time. """
candy_now = await self . config . user ( ctx . author ) . candies ( )
credits_name = await bank . get_currency_name ( ctx . guild )
if pieces < = 0 :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( " Not in this reality. " )
2018-10-13 19:48:42 -07:00
candy_price = int ( round ( await bank . get_balance ( ctx . author ) ) * 0.04 ) * pieces
if candy_price in range ( 0 , 10 ) :
candy_price = pieces * 10
try :
await bank . withdraw_credits ( ctx . author , candy_price )
except ValueError :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( f " Not enough { credits_name } ( { candy_price } required). " )
2018-10-13 19:48:42 -07:00
await self . config . user ( ctx . author ) . candies . set ( candy_now + pieces )
2021-09-28 11:13:05 -07:00
await ctx . reply ( f " Bought { pieces } candies with { candy_price } { credits_name } . " )
2018-10-13 19:48:42 -07:00
@commands.guild_only ( )
@commands.command ( )
2019-10-08 03:21:00 +02:00
@commands.bot_has_permissions ( embed_links = True , add_reactions = True )
2018-10-13 19:48:42 -07:00
async def cboard ( self , ctx ) :
""" Show the candy eating leaderboard. """
userinfo = await self . config . _all_from_scope ( scope = " USER " )
if not userinfo :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( " No one has any candy. " )
2019-10-08 03:49:02 +02:00
async with ctx . typing ( ) :
sorted_acc = sorted ( userinfo . items ( ) , key = lambda x : x [ 1 ] [ " eaten " ] , reverse = True )
2019-10-11 03:02:54 +02:00
# Leaderboard logic from https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/cogs/economy/economy.py#L445
pound_len = len ( str ( len ( sorted_acc ) ) )
score_len = 10
header = " { pound: {pound_len} } { score: {score_len} } {name:2} \n " . format (
pound = " # " ,
pound_len = pound_len + 3 ,
score = " Candies Eaten " ,
score_len = score_len + 6 ,
name = " \N{THIN SPACE} " + " Name "
if not str ( ctx . author . mobile_status ) in [ " online " , " idle " , " dnd " ]
else " Name " ,
)
temp_msg = header
for pos , account in enumerate ( sorted_acc ) :
if account [ 1 ] [ " eaten " ] == 0 :
continue
try :
if account [ 0 ] in [ member . id for member in ctx . guild . members ] :
user_obj = ctx . guild . get_member ( account [ 0 ] )
2019-10-08 03:49:02 +02:00
else :
2019-10-11 03:02:54 +02:00
user_obj = await self . bot . fetch_user ( account [ 0 ] )
except AttributeError :
user_obj = await self . bot . fetch_user ( account [ 0 ] )
2022-10-08 20:05:06 +01:00
_user_name = discord . utils . escape_markdown ( user_obj . name )
user_name = f " { _user_name } # { user_obj . discriminator } "
2019-10-11 03:02:54 +02:00
if len ( user_name ) > 28 :
2022-10-08 20:05:06 +01:00
user_name = f " { _user_name [ : 19 ] } ...# { user_obj . discriminator } "
2019-10-11 03:02:54 +02:00
user_idx = pos + 1
if user_obj == ctx . author :
temp_msg + = (
2019-10-11 03:45:37 +02:00
f " { f ' { user_idx } . ' : < { pound_len + 2 } } "
2019-10-11 03:02:54 +02:00
f " { humanize_number ( account [ 1 ] [ ' eaten ' ] ) + ' 🍬 ' : < { score_len + 4 } } << { user_name } >> \n "
2019-10-08 03:21:00 +02:00
)
2019-10-11 03:02:54 +02:00
else :
temp_msg + = (
2019-10-11 03:45:37 +02:00
f " { f ' { user_idx } . ' : < { pound_len + 2 } } "
2019-10-11 03:02:54 +02:00
f " { humanize_number ( account [ 1 ] [ ' eaten ' ] ) + ' 🍬 ' : < { score_len + 4 } } { user_name } \n "
)
page_list = [ ]
pages = 1
for page in pagify ( temp_msg , delims = [ " \n " ] , page_length = 1000 ) :
embed = discord . Embed (
colour = 0xF4731C ,
2021-09-28 11:13:05 -07:00
description = box ( f " \N{CANDY} Global Leaderboard \N{CANDY} " , lang = " prolog " ) + ( box ( page , lang = " md " ) ) ,
2019-10-11 03:02:54 +02:00
)
2020-08-26 17:57:43 +01:00
embed . set_footer ( text = f " Page { humanize_number ( pages ) } / { humanize_number ( math . ceil ( len ( temp_msg ) / 1500 ) ) } " )
2019-10-11 03:02:54 +02:00
pages + = 1
page_list . append ( embed )
2019-10-08 03:49:02 +02:00
return await menu ( ctx , page_list , DEFAULT_CONTROLS )
2018-10-13 19:48:42 -07:00
@commands.guild_only ( )
@commands.command ( )
2019-10-11 03:02:54 +02:00
@commands.bot_has_permissions ( embed_links = True )
2018-10-13 19:48:42 -07:00
async def cinventory ( self , ctx ) :
""" Check your inventory. """
userdata = await self . config . user ( ctx . author ) . all ( )
2019-10-11 03:02:54 +02:00
sickness = userdata [ " sickness " ]
msg = f " { ctx . author . mention } ' s Candy Bag: "
em = discord . Embed ( color = await ctx . embed_color ( ) )
em . description = f " { userdata [ ' candies ' ] } \N{CANDY} "
2020-10-05 09:57:01 -07:00
if userdata [ " chocolate " ] :
em . description + = f " \n { userdata [ ' chocolate ' ] } \N{CHOCOLATE BAR} "
2018-10-13 19:48:42 -07:00
if userdata [ " lollipops " ] :
2019-10-11 03:02:54 +02:00
em . description + = f " \n { userdata [ ' lollipops ' ] } \N{LOLLIPOP} "
2022-10-06 22:42:10 +01:00
if userdata [ " cookies " ] :
em . description + = f " \n { userdata [ ' cookies ' ] } \N{FORTUNE COOKIE} "
2018-10-13 19:48:42 -07:00
if userdata [ " stars " ] :
2019-10-11 03:02:54 +02:00
em . description + = f " \n { userdata [ ' stars ' ] } \N{WHITE MEDIUM STAR} "
if sickness in range ( 41 , 56 ) :
em . description + = f " \n \n **Sickness is over 40/100** \n *You don ' t feel so good...* "
elif sickness in range ( 56 , 71 ) :
em . description + = f " \n \n **Sickness is over 55/100** \n *You don ' t feel so good...* "
elif sickness in range ( 71 , 86 ) :
2020-08-26 17:57:43 +01:00
em . description + = f " \n \n **Sickness is over 70/100** \n *You really don ' t feel so good...* "
2019-10-11 03:02:54 +02:00
elif sickness in range ( 86 , 101 ) :
em . description + = f " \n \n **Sickness is over 85/100** \n *The thought of more sugar makes you feel awful...* "
elif sickness > 100 :
2020-08-26 17:57:43 +01:00
em . description + = f " \n \n **Sickness is over 100/100** \n *Better wait a while for more candy...* "
2019-10-11 03:02:54 +02:00
await ctx . send ( msg , embed = em )
2018-10-13 19:48:42 -07:00
2021-09-27 09:42:06 -07:00
@commands.guild_only ( )
@checks.is_owner ( )
@commands.command ( )
async def totclearall ( self , ctx , are_you_sure = False ) :
""" [Owner] Clear all saved game data. """
if not are_you_sure :
msg = " This will clear ALL saved data for this cog and reset it to the defaults. \n "
msg + = f " If you are absolutely sure you want to do this, use ` { ctx . prefix } totclearall yes`. "
return await ctx . send ( msg )
await self . config . clear_all ( )
await ctx . send ( " All data for this cog has been cleared. " )
2018-10-13 19:48:42 -07:00
@commands.guild_only ( )
@checks.mod_or_permissions ( administrator = True )
@commands.command ( )
2019-10-02 08:17:56 -07:00
async def totcooldown ( self , ctx , cooldown_time : int = 0 ) :
2018-10-13 19:48:42 -07:00
""" Set the cooldown time for trick or treating on the server. """
2019-10-03 18:05:28 -07:00
if cooldown_time < 0 :
return await ctx . send ( " Nice try. " )
2019-10-03 17:53:18 -07:00
if cooldown_time == 0 :
2018-10-13 19:48:42 -07:00
await self . config . guild ( ctx . guild ) . cooldown . set ( 300 )
2019-10-03 17:53:18 -07:00
return await ctx . send ( " Trick or treating cooldown time reset to 5m. " )
elif 1 < = cooldown_time < = 30 :
await self . config . guild ( ctx . guild ) . cooldown . set ( 30 )
return await ctx . send ( " Trick or treating cooldown time set to the minimum of 30s. " )
2018-10-13 19:48:42 -07:00
else :
await self . config . guild ( ctx . guild ) . cooldown . set ( cooldown_time )
await ctx . send ( f " Trick or treating cooldown time set to { cooldown_time } s. " )
@commands.guild_only ( )
@commands.cooldown ( 1 , 600 , discord . ext . commands . BucketType . user )
@commands.command ( )
2018-12-18 16:01:16 -08:00
async def pickup ( self , ctx ) :
2018-10-13 19:48:42 -07:00
""" Pick up some candy, if there is any. """
candies = await self . config . user ( ctx . author ) . candies ( )
to_pick = await self . config . guild ( ctx . guild ) . pick ( )
chance = random . randint ( 1 , 100 )
found = round ( ( chance / 100 ) * to_pick )
await self . config . user ( ctx . author ) . candies . set ( candies + found )
await self . config . guild ( ctx . guild ) . pick . set ( to_pick - found )
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " You start searching the area for candy... " )
2018-10-17 15:37:12 -07:00
await asyncio . sleep ( 3 )
await message . edit ( content = f " You found { found } \N{CANDY} ! " )
2018-10-13 19:48:42 -07:00
@commands.guild_only ( )
@commands.cooldown ( 1 , 600 , discord . ext . commands . BucketType . user )
@commands.command ( )
2020-10-02 09:47:51 -07:00
async def stealcandy ( self , ctx , user : discord . Member = None ) :
2018-10-13 19:48:42 -07:00
""" Steal some candy. """
2018-10-14 17:02:01 -07:00
guild_users = [ m . id for m in ctx . guild . members if m is not m . bot and not m == ctx . author ]
candy_users = await self . config . _all_from_scope ( scope = " USER " )
valid_user = list ( set ( guild_users ) & set ( candy_users ) )
2021-09-27 09:47:24 -07:00
if not valid_user :
2021-09-28 11:13:05 -07:00
return await ctx . reply ( " No one has any candy yet! " )
2018-10-14 17:56:26 -07:00
if not user :
picked_user = self . bot . get_user ( random . choice ( valid_user ) )
elif user == ctx . author or user == user . bot :
2018-10-14 17:02:01 -07:00
picked_user = self . bot . get_user ( random . choice ( valid_user ) )
2018-10-14 17:59:37 -07:00
elif user != ctx . author or user != user . bot :
2018-10-14 17:02:01 -07:00
picked_user = user
else :
picked_user = self . bot . get_user ( random . choice ( valid_user ) )
2018-10-13 19:48:42 -07:00
picked_candy_now = await self . config . user ( picked_user ) . candies ( )
2018-10-14 17:02:01 -07:00
if picked_candy_now == 0 :
chance = random . randint ( 1 , 25 )
if chance in range ( 21 , 25 ) :
new_picked_user = self . bot . get_user ( random . choice ( valid_user ) )
new_picked_candy_now = await self . config . user ( new_picked_user ) . candies ( )
if chance in range ( 24 , 25 ) :
if new_picked_candy_now == 0 :
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " You see an unsuspecting guildmate... " )
2018-10-17 15:37:12 -07:00
await asyncio . sleep ( random . randint ( 3 , 6 ) )
2018-10-14 17:02:01 -07:00
return await message . edit (
content = f " There was nothing in { picked_user . name } # { picked_user . discriminator } ' s pockets, so you picked { new_picked_user . name } # { new_picked_user . discriminator } ' s pockets but they had no candy either! "
)
else :
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " You see an unsuspecting guildmate... " )
2018-10-17 15:37:12 -07:00
await asyncio . sleep ( random . randint ( 3 , 6 ) )
2018-10-14 17:02:01 -07:00
return await message . edit (
2018-10-17 15:37:12 -07:00
content = f " There was nothing in { picked_user . name } # { picked_user . discriminator } ' s pockets, so you looked around again... you saw { new_picked_user . name } # { new_picked_user . discriminator } in the distance, but you didn ' t think you could catch up... "
2018-10-14 17:02:01 -07:00
)
if chance in range ( 10 , 20 ) :
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " You start sneaking around in the shadows... " )
2018-10-14 17:02:01 -07:00
await asyncio . sleep ( random . randint ( 3 , 6 ) )
return await message . edit (
content = f " You snuck up on { picked_user . name } # { picked_user . discriminator } and tried picking their pockets but there was nothing there! "
)
else :
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " You start looking around for a target... " )
2018-10-14 17:02:01 -07:00
await asyncio . sleep ( random . randint ( 3 , 6 ) )
2020-08-26 17:57:43 +01:00
return await message . edit ( content = " You snuck around for a while but didn ' t find anything. " )
2018-10-13 19:48:42 -07:00
user_candy_now = await self . config . user ( ctx . author ) . candies ( )
multip = random . randint ( 1 , 100 ) / 100
2018-10-14 17:02:01 -07:00
if multip > 0.7 :
multip = 0.7
pieces = round ( picked_candy_now * multip )
if pieces < = 0 :
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " You stealthily move over to an unsuspecting person... " )
2018-10-14 17:02:01 -07:00
await asyncio . sleep ( 4 )
2020-08-26 17:57:43 +01:00
return await message . edit ( content = " You found someone to pickpocket, but they had nothing but pocket lint. " )
2018-10-14 17:02:01 -07:00
chance = random . randint ( 1 , 25 )
sneak_phrases = [
" You look around furtively... " ,
" You glance around slowly, looking for your target... " ,
" You see someone with a full candy bag... " ,
]
if chance < = 10 :
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( " You creep closer to the target... " )
2018-10-16 21:28:56 -07:00
await asyncio . sleep ( random . randint ( 3 , 5 ) )
2020-08-26 17:57:43 +01:00
return await message . edit ( content = " You snuck around for a while but didn ' t find anything. " )
2018-10-14 17:02:01 -07:00
if chance > 18 :
await self . config . user ( picked_user ) . candies . set ( picked_candy_now - pieces )
await self . config . user ( ctx . author ) . candies . set ( user_candy_now + pieces )
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( random . choice ( sneak_phrases ) )
2018-10-17 15:37:12 -07:00
await asyncio . sleep ( 4 )
await message . edit ( content = " There seems to be an unsuspecting victim in the corner... " )
await asyncio . sleep ( 4 )
2018-10-14 17:42:32 -07:00
return await message . edit (
content = f " You stole { pieces } \N{CANDY} from { picked_user . name } # { picked_user . discriminator } ! "
)
2018-10-14 17:02:01 -07:00
if chance in range ( 11 , 17 ) :
await self . config . user ( picked_user ) . candies . set ( picked_candy_now - round ( pieces / 2 ) )
await self . config . user ( ctx . author ) . candies . set ( user_candy_now + round ( pieces / 2 ) )
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( random . choice ( sneak_phrases ) )
2018-10-17 15:37:12 -07:00
await asyncio . sleep ( 4 )
await message . edit ( content = " There seems to be an unsuspecting victim in the corner... " )
await asyncio . sleep ( 4 )
2018-10-14 17:42:32 -07:00
return await message . edit (
content = f " You stole { round ( pieces / 2 ) } \N{CANDY} from { picked_user . name } # { picked_user . discriminator } ! "
)
2018-10-16 21:28:56 -07:00
else :
2021-09-28 11:13:05 -07:00
message = await ctx . reply ( random . choice ( sneak_phrases ) )
2018-10-17 15:37:12 -07:00
await asyncio . sleep ( 4 )
2018-10-16 21:28:56 -07:00
noise_msg = [
" You hear a sound behind you! When you turn back, your target is gone. " ,
" You look away for a moment and your target has vanished. " ,
" Something flashes in your peripheral vision, and as you turn to look, your target gets away... " ,
]
await message . edit ( content = random . choice ( noise_msg ) )
2018-10-13 19:48:42 -07:00
@commands.guild_only ( )
2018-10-14 20:29:14 -07:00
@checks.mod_or_permissions ( administrator = True )
2018-10-13 19:48:42 -07:00
@commands.group ( )
async def totchannel ( self , ctx ) :
""" Channel management for Trick or Treat. """
2020-08-26 17:57:43 +01:00
if ctx . invoked_subcommand is not None or isinstance ( ctx . invoked_subcommand , commands . Group ) :
2018-10-13 19:48:42 -07:00
return
channel_list = await self . config . guild ( ctx . guild ) . channel ( )
channel_msg = " Trick or Treat Channels: \n "
for chan in channel_list :
channel_obj = self . bot . get_channel ( chan )
2020-10-06 10:56:50 -04:00
if channel_obj :
channel_msg + = f " { channel_obj . name } \n "
2018-10-13 19:48:42 -07:00
await ctx . send ( box ( channel_msg ) )
@commands.guild_only ( )
@totchannel.command ( )
async def add ( self , ctx , channel : discord . TextChannel ) :
""" Add a text channel for Trick or Treating. """
channel_list = await self . config . guild ( ctx . guild ) . channel ( )
if channel . id not in channel_list :
channel_list . append ( channel . id )
await self . config . guild ( ctx . guild ) . channel . set ( channel_list )
await ctx . send ( f " { channel . mention } added to the valid Trick or Treat channels. " )
else :
await ctx . send ( f " { channel . mention } is already in the list of Trick or Treat channels. " )
@commands.guild_only ( )
@totchannel.command ( )
async def remove ( self , ctx , channel : discord . TextChannel ) :
""" Remove a text channel from Trick or Treating. """
channel_list = await self . config . guild ( ctx . guild ) . channel ( )
if channel . id in channel_list :
channel_list . remove ( channel . id )
else :
return await ctx . send ( f " { channel . mention } not in whitelist. " )
await self . config . guild ( ctx . guild ) . channel . set ( channel_list )
await ctx . send ( f " { channel . mention } removed from the list of Trick or Treat channels. " )
@commands.guild_only ( )
2018-10-14 20:26:32 -07:00
@checks.mod_or_permissions ( administrator = True )
2018-10-13 19:48:42 -07:00
@commands.command ( )
async def tottoggle ( self , ctx ) :
""" Toggle trick or treating on the whole server. """
toggle = await self . config . guild ( ctx . guild ) . toggle ( )
msg = f " Trick or Treating active: { not toggle } . \n "
channel_list = await self . config . guild ( ctx . guild ) . channel ( )
if not channel_list :
channel_list . append ( ctx . message . channel . id )
await self . config . guild ( ctx . guild ) . channel . set ( channel_list )
msg + = f " Trick or Treating channel added: { ctx . message . channel . mention } "
await self . config . guild ( ctx . guild ) . toggle . set ( not toggle )
await ctx . send ( msg )
2018-10-14 17:02:01 -07:00
@commands.guild_only ( )
2020-10-05 07:51:10 -07:00
@commands.command ( hidden = True )
2018-10-14 17:02:01 -07:00
async def totversion ( self , ctx ) :
""" Trick or Treat version. """
2020-10-05 07:51:10 -07:00
await ctx . send ( f " Trick or Treat version { __version__ } " )
async def has_perm ( self , user ) :
return await self . bot . allowed_by_whitelist_blacklist ( user )
2018-10-14 17:02:01 -07:00
2019-10-02 08:17:56 -07:00
@commands.Cog.listener ( )
2020-10-05 07:51:10 -07:00
async def on_message_without_command ( self , message ) :
2018-10-13 19:48:42 -07:00
if isinstance ( message . channel , discord . abc . PrivateChannel ) :
return
if message . author . bot :
return
2020-10-05 07:51:10 -07:00
if not await self . has_perm ( message . author ) :
return
2018-10-13 19:48:42 -07:00
chance = random . randint ( 1 , 12 )
if chance % 4 == 0 :
sickness_now = await self . config . user ( message . author ) . sickness ( )
sick_chance = random . randint ( 1 , 12 )
if sick_chance % 3 == 0 :
new_sickness = sickness_now - sick_chance
if new_sickness < 0 :
new_sickness = 0
await self . config . user ( message . author ) . sickness . set ( new_sickness )
2020-10-05 07:51:10 -07:00
pick_chance = random . randint ( 1 , 12 )
if pick_chance % 4 == 0 :
random_candies = random . randint ( 1 , 3 )
guild_pool = await self . config . guild ( message . guild ) . pick ( )
await self . config . guild ( message . guild ) . pick . set ( guild_pool + random_candies )
content = ( message . content ) . lower ( )
2019-10-03 20:57:50 +02:00
if not content . startswith ( " trick or treat " ) :
2018-10-13 19:48:42 -07:00
return
toggle = await self . config . guild ( message . guild ) . toggle ( )
if not toggle :
return
channel = await self . config . guild ( message . guild ) . channel ( )
if message . channel . id not in channel :
return
userdata = await self . config . user ( message . author ) . all ( )
last_time = datetime . datetime . strptime ( str ( userdata [ " last_tot " ] ) , " % Y- % m- %d % H: % M: % S. %f " )
now = datetime . datetime . now ( datetime . timezone . utc )
now = now . replace ( tzinfo = None )
2020-08-26 17:57:43 +01:00
if int ( ( now - last_time ) . total_seconds ( ) ) < await self . config . guild ( message . guild ) . cooldown ( ) :
2018-10-13 19:48:42 -07:00
messages = [
" The thought of candy right now doesn ' t really sound like a good idea. " ,
" All the lights on this street are dark... " ,
" It ' s starting to get late. " ,
2018-10-16 21:28:56 -07:00
" The wind howls through the trees. Does it seem darker all of a sudden? " ,
" You start to walk the long distance to the next house... " ,
" You take a moment to count your candy before moving on. " ,
" The house you were approaching just turned the light off. " ,
" The wind starts to pick up as you look for the next house... " ,
2018-10-13 19:48:42 -07:00
]
2021-09-28 11:13:05 -07:00
return await message . reply ( random . choice ( messages ) )
2019-10-01 19:45:28 -07:00
await self . config . user ( message . author ) . last_tot . set ( str ( now ) )
2018-10-13 19:48:42 -07:00
candy = random . randint ( 1 , 25 )
lollipop = random . randint ( 0 , 100 )
star = random . randint ( 0 , 100 )
2020-10-05 07:51:10 -07:00
chocolate = random . randint ( 0 , 100 )
2022-10-06 22:42:10 +01:00
cookie = random . randint ( 0 , 100 )
2020-10-05 07:51:10 -07:00
win_message = f " { message . author . mention } \n You received: \n { candy } \N{CANDY} "
2018-10-17 15:37:12 -07:00
await self . config . user ( message . author ) . candies . set ( userdata [ " candies " ] + candy )
2020-10-05 07:51:10 -07:00
if chocolate == 100 :
2021-09-27 09:42:06 -07:00
await self . config . user ( message . author ) . chocolate . set ( userdata [ " chocolate " ] + 6 )
win_message + = " \n **BONUS**: 6 \N{CHOCOLATE BAR} "
2020-10-05 07:51:10 -07:00
elif 99 > = chocolate > = 95 :
2021-09-27 09:42:06 -07:00
await self . config . user ( message . author ) . chocolate . set ( userdata [ " chocolate " ] + 5 )
win_message + = " \n **BONUS**: 5 \N{CHOCOLATE BAR} "
2020-10-05 07:51:10 -07:00
elif 94 > = chocolate > = 90 :
2021-09-27 09:42:06 -07:00
await self . config . user ( message . author ) . chocolate . set ( userdata [ " chocolate " ] + 4 )
win_message + = " \n **BONUS**: 4 \N{CHOCOLATE BAR} "
elif 89 > = chocolate > = 80 :
await self . config . user ( message . author ) . chocolate . set ( userdata [ " chocolate " ] + 3 )
win_message + = " \n **BONUS**: 3 \N{CHOCOLATE BAR} "
elif 79 > = chocolate > = 75 :
2020-10-05 07:51:10 -07:00
await self . config . user ( message . author ) . chocolate . set ( userdata [ " chocolate " ] + 2 )
win_message + = " \n **BONUS**: 2 \N{CHOCOLATE BAR} "
2021-09-27 09:42:06 -07:00
elif 74 > = chocolate > = 70 :
2020-10-05 07:51:10 -07:00
await self . config . user ( message . author ) . chocolate . set ( userdata [ " chocolate " ] + 1 )
win_message + = " \n **BONUS**: 1 \N{CHOCOLATE BAR} "
if lollipop == 100 :
2021-09-27 09:42:06 -07:00
await self . config . user ( message . author ) . lollipops . set ( userdata [ " lollipops " ] + 4 )
win_message + = " \n **BONUS**: 4 \N{LOLLIPOP} "
elif 99 > = lollipop > = 95 :
2020-10-05 07:51:10 -07:00
await self . config . user ( message . author ) . lollipops . set ( userdata [ " lollipops " ] + 3 )
win_message + = " \n **BONUS**: 3 \N{LOLLIPOP} "
2021-09-27 09:42:06 -07:00
elif 94 > = lollipop > = 85 :
2020-10-05 07:51:10 -07:00
await self . config . user ( message . author ) . lollipops . set ( userdata [ " lollipops " ] + 2 )
win_message + = " \n **BONUS**: 2 \N{LOLLIPOP} "
2021-09-27 09:42:06 -07:00
elif 84 > = lollipop > = 75 :
2018-10-17 15:37:12 -07:00
await self . config . user ( message . author ) . lollipops . set ( userdata [ " lollipops " ] + 1 )
2020-10-05 07:51:10 -07:00
win_message + = " \n **BONUS**: 1 \N{LOLLIPOP} "
2022-10-06 22:42:10 +01:00
if cookie == 100 :
await self . config . user ( message . author ) . cookies . set ( userdata [ " cookies " ] + 4 )
win_message + = " \n **BONUS**: 4 \N{FORTUNE COOKIE} "
elif 99 > = cookie > = 97 :
await self . config . user ( message . author ) . cookies . set ( userdata [ " cookies " ] + 3 )
win_message + = " \n **BONUS**: 3 \N{FORTUNE COOKIE} "
elif 96 > = cookie > = 85 :
await self . config . user ( message . author ) . cookies . set ( userdata [ " cookies " ] + 2 )
win_message + = " \n **BONUS**: 2 \N{FORTUNE COOKIE} "
elif 84 > = cookie > = 75 :
await self . config . user ( message . author ) . cookies . set ( userdata [ " cookies " ] + 1 )
win_message + = " \n **BONUS**: 1 \N{FORTUNE COOKIE} "
2020-10-05 07:51:10 -07:00
if star == 100 :
2021-09-27 09:42:06 -07:00
await self . config . user ( message . author ) . stars . set ( userdata [ " stars " ] + 4 )
win_message + = " \n **BONUS**: 4 \N{WHITE MEDIUM STAR} "
elif 99 > = star > = 97 :
2020-10-05 07:51:10 -07:00
await self . config . user ( message . author ) . stars . set ( userdata [ " stars " ] + 3 )
win_message + = " \n **BONUS**: 3 \N{WHITE MEDIUM STAR} "
2021-09-27 09:42:06 -07:00
elif 96 > = star > = 85 :
2020-10-05 07:51:10 -07:00
await self . config . user ( message . author ) . stars . set ( userdata [ " stars " ] + 2 )
win_message + = " \n **BONUS**: 2 \N{WHITE MEDIUM STAR} "
2021-09-27 09:42:06 -07:00
elif 84 > = star > = 75 :
2018-10-17 15:37:12 -07:00
await self . config . user ( message . author ) . stars . set ( userdata [ " stars " ] + 1 )
2020-10-05 07:51:10 -07:00
win_message + = " \n **BONUS**: 1 \N{WHITE MEDIUM STAR} "
2018-10-17 15:37:12 -07:00
2018-10-13 19:48:42 -07:00
walking_messages = [
" *You hear footsteps...* " ,
" *You ' re left alone with your thoughts as you wait for the door to open...* " ,
" *The wind howls through the trees...* " ,
" *Does it feel colder out here all of a sudden?* " ,
" *Somewhere inside the house, you hear wood creaking...* " ,
2018-10-16 21:28:56 -07:00
" *You walk up the path to the door and knock...* " ,
" *You knock on the door...* " ,
" *There ' s a movement in the shadows by the side of the house...* " ,
2018-10-13 19:48:42 -07:00
]
2021-09-28 11:13:05 -07:00
bot_talking = await message . reply ( random . choice ( walking_messages ) )
2018-10-13 19:48:42 -07:00
await asyncio . sleep ( random . randint ( 5 , 8 ) )
door_messages = [
" *The door slowly opens...* " ,
" *The ancient wooden door starts to open...* " ,
" *A light turns on overhead...* " ,
" *You hear a scuffling noise...* " ,
2018-10-16 21:28:56 -07:00
" *There ' s someone talking inside...* " ,
" *The wind whips around your feet...* " ,
" *A crow caws ominously...* " ,
" *You hear an owl hooting in the distance...* " ,
2018-10-13 19:48:42 -07:00
]
await bot_talking . edit ( content = random . choice ( door_messages ) )
await asyncio . sleep ( random . randint ( 5 , 8 ) )
greet_messages = [
" Oh, hello. What a cute costume. Here, have some candy. " ,
" Look at that costume. Here you go. " ,
" Out this late at night? " ,
" Here ' s a little something for you. " ,
" The peppermint ones are my favorite. " ,
" Come back again later if you see the light on still. " ,
2018-10-16 21:28:56 -07:00
" Go ahead, take a few. " ,
" Here you go. " ,
" Aww, look at you. Here, take this. " ,
" Don ' t eat all those at once! " ,
" Well, I think this is the last of it. Go ahead and take it. " ,
" *I hear the next door neighbors have some pretty good candy too, this year.* " ,
2018-10-13 19:48:42 -07:00
]
await bot_talking . edit ( content = random . choice ( greet_messages ) )
await asyncio . sleep ( 2 )
await message . channel . send ( win_message )