Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions DiscordBot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import requests
from report import Report
import pdb
from discord.ui import Button, View

# Set up logging to the console
logger = logging.getLogger('discord')
Expand All @@ -30,7 +31,8 @@ class ModBot(discord.Client):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__(command_prefix='.', intents=intents)
intents.members = True # Need this for blocking users
super().__init__(intents=intents)
self.group_num = None
self.mod_channels = {} # Map from guild to the mod channel id for that guild
self.reports = {} # Map from user IDs to the state of their report
Expand Down Expand Up @@ -73,7 +75,7 @@ async def on_message(self, message):
async def handle_dm(self, message):
# Handle a help message
if message.content == Report.HELP_KEYWORD:
reply = "Use the `report` command to begin the reporting process.\n"
reply = "Use the `report` command to begin the reporting process.\n"
reply += "Use the `cancel` command to cancel the report process.\n"
await message.channel.send(reply)
return
Expand All @@ -89,10 +91,16 @@ async def handle_dm(self, message):
if author_id not in self.reports:
self.reports[author_id] = Report(self)

# Let the report class handle this message; forward all the messages it returns to uss
# Let the report class handle this message; forward all the messages it returns to us
responses = await self.reports[author_id].handle_message(message)
for r in responses:
await message.channel.send(r)
for response in responses:
if isinstance(response, tuple) and len(response) == 2:
# If response is a tuple of (message, view)
msg, view = response
await message.channel.send(msg, view=view)
else:
# Regular string message
await message.channel.send(response)

# If the report is complete or cancelled, remove it from our map
if self.reports[author_id].report_complete():
Expand Down Expand Up @@ -126,6 +134,14 @@ def code_format(self, text):
'''
return "Evaluated: '" + text+ "'"

async def block_user(self, user_to_block, blocked_by):
"""Implement the logic to block a user"""
try:
await blocked_by.block(user_to_block)
return True
except discord.errors.HTTPException:
return False


client = ModBot()
client.run(discord_token)
Loading