1
+ from asyncio import TimeoutError as AsyncTimeoutError
2
+
1
3
from redbot .core import commands
4
+ from redbot .core .utils .predicates import MessagePredicate
2
5
3
6
from leveler .abc import MixinMeta
4
7
@@ -14,53 +17,95 @@ class Backgrounds(MixinMeta):
14
17
@commands .is_owner ()
15
18
@commands .guild_only ()
16
19
async def lvladminbg (self , ctx ):
17
- """Admin background configuration"""
20
+ """Backgrounds configuration. """
18
21
pass
19
22
20
23
@lvladminbg .command ()
21
24
async def addprofilebg (self , ctx , name : str , url : str ):
22
25
"""Add a profile background.
23
26
24
27
The proportions must be 290px x 290px."""
25
- backgrounds = await self .config .backgrounds ()
26
- if name in backgrounds ["profile" ].keys ():
27
- await ctx .send ("That profile background name already exists!" )
28
- elif not await self ._valid_image_url (url ):
28
+ if not await self ._valid_image_url (url ):
29
29
await ctx .send ("That is not a valid image URL!" )
30
- else :
31
- async with self .config .backgrounds () as backgrounds :
32
- backgrounds ["profile" ][name ] = url
33
- await ctx .send ("New profile background (`{}`) added." .format (name ))
30
+ return
31
+ async with self .config .backgrounds () as backgrounds :
32
+ if name in backgrounds ["profile" ].keys ():
33
+ pred = MessagePredicate .yes_or_no (ctx )
34
+ if not ctx .assume_yes :
35
+ await ctx .send (
36
+ (
37
+ "This will replace already existing background `{name}` "
38
+ "for future users of this background. Do you want to proceed?\n "
39
+ 'To agree, type "yes"'
40
+ ).format (name = name )
41
+ )
42
+ try :
43
+ await self .bot .wait_for ("message" , check = pred , timeout = 30 )
44
+ except AsyncTimeoutError :
45
+ pass
46
+ if not (ctx .assume_yes or pred .result ):
47
+ await ctx .send ("Aborting." )
48
+ return
49
+ backgrounds ["profile" ][name ] = url
50
+ await ctx .send ("New profile background (`{}`) added." .format (name ))
34
51
35
52
@lvladminbg .command ()
36
53
async def addrankbg (self , ctx , name : str , url : str ):
37
54
"""Add a rank background.
38
55
39
56
The proportions must be 360px x 100px."""
40
- backgrounds = await self .config .backgrounds ()
41
- if name in backgrounds ["profile" ].keys ():
42
- await ctx .send ("That rank background name already exists!" )
43
- elif not await self ._valid_image_url (url ):
57
+ if not await self ._valid_image_url (url ):
44
58
await ctx .send ("That is not a valid image URL!" )
45
- else :
46
- async with self .config .backgrounds () as backgrounds :
47
- backgrounds ["rank" ][name ] = url
48
- await ctx .send ("New rank background (`{}`) added." .format (name ))
59
+ return
60
+ async with self .config .backgrounds () as backgrounds :
61
+ if name in backgrounds ["rank" ].keys ():
62
+ pred = MessagePredicate .yes_or_no (ctx )
63
+ if not ctx .assume_yes :
64
+ await ctx .send (
65
+ (
66
+ "This will replace already existing background `{name}` "
67
+ "for future users of this background. Do you want to proceed?\n "
68
+ 'To agree, type "yes"'
69
+ ).format (name = name )
70
+ )
71
+ try :
72
+ await self .bot .wait_for ("message" , check = pred , timeout = 30 )
73
+ except AsyncTimeoutError :
74
+ pass
75
+ if not (ctx .assume_yes or pred .result ):
76
+ await ctx .send ("Aborting." )
77
+ return
78
+ backgrounds ["rank" ][name ] = url
79
+ await ctx .send ("New rank background (`{}`) added." .format (name ))
49
80
50
81
@lvladminbg .command ()
51
82
async def addlevelbg (self , ctx , name : str , url : str ):
52
83
"""Add a level-up background.
53
84
54
85
The proportions must be 175px x 65px."""
55
- backgrounds = await self .config .backgrounds ()
56
- if name in backgrounds ["levelup" ].keys ():
57
- await ctx .send ("That level-up background name already exists!" )
58
- elif not await self ._valid_image_url (url ):
86
+ if not await self ._valid_image_url (url ):
59
87
await ctx .send ("That is not a valid image URL!" )
60
- else :
61
- async with self .config .backgrounds () as backgrounds :
62
- backgrounds ["levelup" ][name ] = url
63
- await ctx .send ("New level-up background (`{}`) added." .format (name ))
88
+ return
89
+ async with self .config .backgrounds () as backgrounds :
90
+ if name in backgrounds ["levelup" ].keys ():
91
+ pred = MessagePredicate .yes_or_no (ctx )
92
+ if not ctx .assume_yes :
93
+ await ctx .send (
94
+ (
95
+ "This will replace already existing background `{name}` "
96
+ "for future users of this background. Do you want to proceed?\n "
97
+ 'To agree, type "yes"'
98
+ ).format (name = name )
99
+ )
100
+ try :
101
+ await self .bot .wait_for ("message" , check = pred , timeout = 30 )
102
+ except AsyncTimeoutError :
103
+ pass
104
+ if not (ctx .assume_yes or pred .result ):
105
+ await ctx .send ("Aborting." )
106
+ return
107
+ backgrounds ["levelup" ][name ] = url
108
+ await ctx .send ("New level-up background (`{}`) added." .format (name ))
64
109
65
110
@lvladminbg .command ()
66
111
async def setcustombg (self , ctx , bg_type : str , user_id : str , img_url : str ):
0 commit comments