|
1 | | -import datetime |
2 | | - |
3 | | -import discord |
4 | | -from discord.ext import commands |
5 | | - |
6 | | -from bot import RustBot |
7 | | - |
8 | | - |
9 | | -class Commands(commands.Cog): |
10 | | - def __init__(self, bot: RustBot): |
11 | | - self.bot = bot |
12 | | - |
13 | | - @commands.command() |
14 | | - async def uptime(self, ctx: commands.Context): |
15 | | - """Tells you how long the bot has been up for.""" |
16 | | - |
17 | | - now = datetime.datetime.utcnow() |
18 | | - delta = now - self.bot.uptime |
19 | | - hours, remainder = divmod(int(delta.total_seconds()), 3600) |
20 | | - minutes, seconds = divmod(remainder, 60) |
21 | | - days, hours = divmod(hours, 24) |
22 | | - |
23 | | - fmt = "{h}h {m}m {s}s" |
24 | | - if days: |
25 | | - fmt = "{d}d " + fmt |
26 | | - |
27 | | - await ctx.send( |
28 | | - content="Uptime: {}".format( |
29 | | - fmt.format(d=days, h=hours, m=minutes, s=seconds) |
30 | | - ) |
31 | | - ) |
32 | | - |
33 | | - @commands.command() |
34 | | - async def invite(self, ctx: commands.Context): |
35 | | - """Points the user to the #informational channel, |
36 | | - which contains invite links. |
37 | | - """ |
38 | | - |
39 | | - channel = "<#273547351929520129>" |
40 | | - link = "https://discordapp.com/channels/273534239310479360/273547351929520129/288101969980162049" |
41 | | - await ctx.send(f"Invite links are provided in {channel}\n{link}") |
42 | | - |
43 | | - @commands.command(aliases=["wustify"]) |
44 | | - @commands.guild_only() |
45 | | - async def rustify(self, ctx: commands.Context, *members: discord.Member): |
46 | | - """Adds the Rustacean role to a member. |
47 | | - Takes in a space-separated list of member mentions and/or IDs. |
48 | | - """ |
49 | | - |
50 | | - for member in members: |
51 | | - await member.add_roles( |
52 | | - self.bot.role.rustacean, |
53 | | - reason=f"You have been rusted by {ctx.author}! owo", |
54 | | - ) |
55 | | - |
56 | | - await ctx.message.add_reaction(self.bot.emoji.ok) |
57 | | - |
58 | | - @commands.command() |
59 | | - async def cleanup(self, ctx: commands.Context, limit=None): |
60 | | - """Deletes the bot's messages for cleanup. |
61 | | - You can specify how many messages to look for. |
62 | | - """ |
63 | | - |
64 | | - limit = limit or 100 |
65 | | - |
66 | | - def is_me(m): |
67 | | - return m.author.id == self.bot.user.id |
68 | | - |
69 | | - deleted = await ctx.channel.purge(limit=limit, check=is_me) |
70 | | - await ctx.send(f"Deleted {len(deleted)} message(s)", delete_after=5) |
71 | | - await ctx.message.add_reaction(self.bot.emoji.ok) |
72 | | - |
73 | | - @commands.command() |
74 | | - async def source(self, ctx: commands.Context): |
75 | | - """Links to the bot GitHub repo.""" |
76 | | - |
77 | | - await ctx.send("https://github.com/ivandardi/RustbotPython") |
78 | | - |
79 | | - @commands.command() |
80 | | - async def ban(self, ctx: commands.Context, member: discord.Member): |
81 | | - """Bans another person.""" |
82 | | - await ctx.send(f"{ctx.author} banned user {member} <:ferrisBanne:419884768256327680>") |
83 | | - await ctx.message.add_reaction(self.bot.emoji.ok) |
84 | | - |
85 | | - async def cog_command_error(self, ctx: commands.Context, error): |
86 | | - await ctx.message.clear_reactions() |
87 | | - await ctx.message.add_reaction("❌") |
88 | | - |
89 | | - |
90 | | -def setup(bot): |
91 | | - bot.add_cog(Commands(bot)) |
| 1 | +import datetime |
| 2 | + |
| 3 | +import discord |
| 4 | +from discord.ext import commands |
| 5 | + |
| 6 | +from bot import RustBot |
| 7 | + |
| 8 | + |
| 9 | +class Commands(commands.Cog): |
| 10 | + def __init__(self, bot: RustBot): |
| 11 | + self.bot = bot |
| 12 | + |
| 13 | + @commands.command() |
| 14 | + async def uptime(self, ctx: commands.Context): |
| 15 | + """Tells you how long the bot has been up for.""" |
| 16 | + |
| 17 | + now = datetime.datetime.utcnow() |
| 18 | + delta = now - self.bot.uptime |
| 19 | + hours, remainder = divmod(int(delta.total_seconds()), 3600) |
| 20 | + minutes, seconds = divmod(remainder, 60) |
| 21 | + days, hours = divmod(hours, 24) |
| 22 | + |
| 23 | + fmt = "{h}h {m}m {s}s" |
| 24 | + if days: |
| 25 | + fmt = "{d}d " + fmt |
| 26 | + |
| 27 | + await ctx.send( |
| 28 | + content="Uptime: {}".format( |
| 29 | + fmt.format(d=days, h=hours, m=minutes, s=seconds) |
| 30 | + ) |
| 31 | + ) |
| 32 | + |
| 33 | + @commands.command() |
| 34 | + async def invite(self, ctx: commands.Context): |
| 35 | + """Points the user to the #informational channel, |
| 36 | + which contains invite links. |
| 37 | + """ |
| 38 | + |
| 39 | + channel = "<#273547351929520129>" |
| 40 | + link = "https://discordapp.com/channels/273534239310479360/273547351929520129/288101969980162049" |
| 41 | + await ctx.send(f"Invite links are provided in {channel}\n{link}") |
| 42 | + |
| 43 | + @commands.command(aliases=["wustify"]) |
| 44 | + @commands.guild_only() |
| 45 | + async def rustify(self, ctx: commands.Context, *members: discord.Member): |
| 46 | + """Adds the Rustacean role to a member. |
| 47 | + Takes in a space-separated list of member mentions and/or IDs. |
| 48 | + """ |
| 49 | + |
| 50 | + for member in members: |
| 51 | + await member.add_roles( |
| 52 | + self.bot.role.rustacean, |
| 53 | + reason=f"You have been rusted by {ctx.author}! owo", |
| 54 | + ) |
| 55 | + |
| 56 | + await ctx.message.add_reaction(self.bot.emoji.ok) |
| 57 | + |
| 58 | + @commands.command() |
| 59 | + async def cleanup(self, ctx: commands.Context, limit=None): |
| 60 | + """Deletes the bot's messages for cleanup. |
| 61 | + You can specify how many messages to look for. |
| 62 | + """ |
| 63 | + |
| 64 | + limit = limit or 100 |
| 65 | + |
| 66 | + def is_me(m): |
| 67 | + return m.author.id == self.bot.user.id |
| 68 | + |
| 69 | + deleted = await ctx.channel.purge(limit=limit, check=is_me) |
| 70 | + await ctx.send(f"Deleted {len(deleted)} message(s)", delete_after=5) |
| 71 | + await ctx.message.add_reaction(self.bot.emoji.ok) |
| 72 | + |
| 73 | + @commands.command() |
| 74 | + async def source(self, ctx: commands.Context): |
| 75 | + """Links to the bot GitHub repo.""" |
| 76 | + |
| 77 | + await ctx.send("https://github.com/ivandardi/RustbotPython") |
| 78 | + |
| 79 | + @commands.command() |
| 80 | + async def ban(self, ctx: commands.Context, member: discord.Member): |
| 81 | + """Bans another person.""" |
| 82 | + await ctx.send( |
| 83 | + f"{ctx.author} banned user {member} <:ferrisBanne:419884768256327680>" |
| 84 | + ) |
| 85 | + await ctx.message.add_reaction(self.bot.emoji.ok) |
| 86 | + |
| 87 | + async def cog_command_error(self, ctx: commands.Context, error): |
| 88 | + await ctx.message.clear_reactions() |
| 89 | + await ctx.message.add_reaction("❌") |
| 90 | + |
| 91 | + |
| 92 | +def setup(bot): |
| 93 | + bot.add_cog(Commands(bot)) |
0 commit comments