Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polite 1.0 #32

Open
wants to merge 6 commits into
base: beta
Choose a base branch
from
Open
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
31 changes: 29 additions & 2 deletions unitbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
from datetime import datetime, date

import discord
from discord.channel import TextChannel
from discord.ext import commands
from discord.member import Member

import unitconversion
import unitpedialib
Expand All @@ -39,10 +41,35 @@ async def on_ready():

@bot.event
async def on_message(message): # Catches send messages and corrects non-SI units if neccesary. Most of the code behind this is in 'unitconversion.py'.
if bot.user.id is not message.author.id and message.author.bot is False and (message.guild is None or (message.guild is not None and discord.utils.get(message.guild.roles, name='imperial certified') not in message.author.roles)):
author = message.author
if bot.user.id is not author.id and author.bot is False:
# variables that hold settings and message data
processedMessage = unitconversion.process(message.content)
polite = False
# check bot roles for settings
guild = (await bot.get_context(message)).guild
if guild is not None:
bot_roles = guild.get_member(bot.user.id).roles
for role in bot_roles:
if (str(role) == "polite") or (str(role) == "politeconversions"):
polite = True
break
# check user roles for settings
author = message.author
if isinstance(author, Member):
user_roles = author.roles
for role in user_roles:
if (str(role) == "politeconversions"):
polite = True
if (str(role) == "imperial certified"):
processedMessage = None
# handle settings and message data
if processedMessage is not None:
correctionText = ("I think " + (message.author.display_name if message.guild is not None else "you") + " meant to say: ```" + processedMessage + "```")
name = (message.author.display_name if message.guild is not None else "you")
if polite:
correctionText = "I converted " + name + "'s message to metric units: ```" + processedMessage + "```"
else:
correctionText = "I think " + name + " meant to say: ```" + processedMessage + "```"
await message.channel.send(correctionText)
await bot.process_commands(message)

Expand Down