-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
110 lines (91 loc) · 3.91 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
spame - a discord.py bot made for managing spam channels
Copyright (C) 2024-2025 Butterroach
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import discord
from discord.ext import commands
from dotenv import load_dotenv
from os import environ
load_dotenv()
TOKEN: str = environ["TOKEN"]
CHANNEL_PREFIX: str = environ["SPAM_CHANNEL_PREFIX"]
CHANGERS: list[str] = environ["CHANGERS"]
CASE_SENSITIVE_SPAM: bool = environ["CASE_SENSITIVE"] == "true"
UWU_PWEASE = ", please give me the 'Manage Messages' permission. I do not have the proper permissions to function properly."
spam: str = environ["DEFAULT_SPAM_MESSAGE"]
started_once: bool = False
intents = discord.Intents.default()
intents.message_content = intents.members = True
bot: commands.Bot = commands.Bot("6.28!", intents=intents)
async def clear_n_pin(message: discord.Message | commands.Context) -> bool:
try:
for msg in await message.channel.pins():
await msg.unpin()
await message.pin()
except discord.Forbidden:
await message.channel.send(f"{message.guild.owner.mention}{UWU_PWEASE}")
return False
return True
async def wrong_message_handle(message: discord.Message) -> None:
try:
await message.delete()
except discord.Forbidden:
await message.channel.send(f"{message.guild.owner.mention}{UWU_PWEASE}")
else:
await message.channel.send(
f"{message.author.mention}, you MUST send the current spam message __ONLY__. It is in my most recent pinned message!",
delete_after=5,
)
@bot.event
async def on_ready() -> None:
print("haiiii :3")
if not started_once:
for channel in bot.get_all_channels():
if channel.name.startswith(CHANNEL_PREFIX):
bot_message: discord.Message = await channel.send(
f"The bot has restarted, and the spam message has been reset. The spam message is now set to:\n\n```\n{spam}\n```"
)
await clear_n_pin(bot_message)
@bot.event
async def on_message(message: discord.Message) -> None:
await bot.process_commands(message)
if not message.channel.name.startswith(
CHANNEL_PREFIX
) or message.content.startswith(bot.command_prefix):
return
if message.type == discord.MessageType.pins_add and message.author == bot.user:
print(".")
await message.delete()
if message.author.bot:
return
if CASE_SENSITIVE_SPAM:
if message.content != spam:
await wrong_message_handle(message)
return
if message.content.casefold() != spam.casefold():
await wrong_message_handle(message)
@bot.command()
async def newspam(ctx: commands.Context, *, new_spam_message: str = None):
global spam
if str(ctx.author.id) not in CHANGERS and "*" not in CHANGERS:
await ctx.reply("You're not a changer! You can NOT change the spam message!")
return
if new_spam_message is None:
await ctx.reply("Provide something!")
return
spam = new_spam_message
bot_message: discord.Message = await ctx.send(
f"# A NEW SPAM MESSAGE HAS BEEN SET!\n\n```\n{spam}\n```"
)
await clear_n_pin(bot_message)
bot.run(TOKEN)