Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Rest of v7 besides abbv stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliott Pardee committed Jul 30, 2018
1 parent 7fb610c commit 857b8f9
Show file tree
Hide file tree
Showing 14 changed files with 493 additions and 286 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -108,6 +108,7 @@ venv.bak/
databases/db
databases/bandb
databases/guilddb
databases/optoutdb

# ignore config file
src/config.ini
Expand Down
2 changes: 1 addition & 1 deletion .idea/BibleBot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

535 changes: 297 additions & 238 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ source venv/bin/activate
cp src/config.example.ini src/config.ini
$EDITOR src/config.ini
pip install -U "https://github.com/Rapptz/discord.py/archive/rewrite.zip#egg=discord.py[voice]"
pip install -U tinydb colorama requests bs4
pip install -U tinydb colorama requests bs4 lxml
python src/bot.py
```

Expand Down
15 changes: 14 additions & 1 deletion src/bible_modules/biblegateway.py
Expand Up @@ -114,11 +114,24 @@ def get_result(query, version, headings, verse_numbers):
for heading in div.find_all("h3"):
title += heading.get_text() + " / "

for note in div.find_all(True, {"class": "first-line-none"}):
note.decompose()

for inline in div.find_all(True, {"class": "inline-h3"}):
inline.decompose()

for footnote in div.find_all(True, {"class": "footnotes"}):
footnote.decompose()

if verse_numbers == "disable":
for num in div.find_all(True, {"class": ["chapternum", "versenum"]}):
num.string = " "
else:
for num in div.find_all(True, {"class": ["chapternum", "versenum"]}):
# turn all chapter numbers into "1" otherwise the verse numbers look strange
for num in div.find_all(True, {"class": "chapternum"}):
num.string = "<1> "

for num in div.find_all(True, {"class": "versenum"}):
num.string = "<" + num.string[0:-1] + "> "

for meta in div.find_all(True, {"class": ["crossreference", "footnote"]}):
Expand Down
4 changes: 2 additions & 2 deletions src/bible_modules/bibleutils.py
Expand Up @@ -23,10 +23,10 @@


def purify_text(text):
result = text.replace("“", " \"")
result = text.replace("“", "\"")
result = result.replace("[", " <")
result = result.replace("]", "> ")
result = result.replace("”", "\" ")
result = result.replace("”", "\"")
result = result.replace("‘", "'")
result = result.replace("’", "'")
result = result.replace(",", ", ")
Expand Down
65 changes: 33 additions & 32 deletions src/bot.py
Expand Up @@ -156,7 +156,7 @@ async def run_timed_votds(self):
await asyncio.sleep(60)

async def on_message(self, raw):
self.wait_until_ready()
await self.wait_until_ready()

sender = raw.author
identifier = sender.name + "#" + sender.discriminator
Expand All @@ -171,6 +171,9 @@ async def on_message(self, raw):
if sender == self.user:
return

if central.is_optout(str(sender.id)):
return

language = languages.get_language(sender)

if hasattr(channel, "guild"):
Expand Down Expand Up @@ -251,17 +254,21 @@ async def on_message(self, raw):

if "isError" not in res:
if guild is not None:
if central.is_banned(str(guild.id)):
await channel.send("This server has been banned from using BibleBot.")
is_banned, reason = central.is_banned(str(guild.id))
if is_banned:
await channel.send("This server has been banned from using BibleBot. Reason: `" +
reason + "`.")
await channel.send("If this is invalid, the server owner may appeal by contacting " +
"vypr#9944.")
"vypr#0001.")

central.log_message("err", shard, identifier, source, "Server is banned.")
return

if central.is_banned(str(sender.id)):
await channel.send(sender.mention + " You have been banned from using BibleBot.")
await channel.send("You may appeal by contacting vypr#9944.")
is_banned, reason = central.is_banned(str(sender.id))
if is_banned:
await channel.send(sender.mention + " You have been banned from using BibleBot. " +
"Reason: `" + reason + "`.")
await channel.send("You may appeal by contacting vypr#0001.")

central.log_message("err", shard, identifier, source, "User is banned.")
return
Expand Down Expand Up @@ -306,7 +313,7 @@ def check(r, u):
await reaction.message.edit(embed=res["pages"][self.current_page - 1])

except (asyncio.TimeoutError, IndexError):
msg.clear_reactions()
await msg.clear_reactions()
else:
if "reference" not in res and "text" not in res:
# noinspection PyBroadException
Expand All @@ -321,24 +328,14 @@ def check(r, u):
await channel.send("Done.")

for original_command_name in raw_language["commands"].keys():
untranslated = ["setlanguage", "userid", "ban", "unban",
"reason", "optout", "unoptout", "eval",
"jepekula", "joseph", "tiger"]

if raw_language["commands"][original_command_name] == command:
original_command = original_command_name
elif command == "setlanguage":
original_command = "setlanguage"
elif command == "userid":
original_command = "userid"
elif command == "ban":
original_command = "ban"
elif command == "unban":
original_command = "unban"
elif command == "eval":
original_command = "eval"
elif command == "jepekula":
original_command = "jepekula"
elif command == "joseph":
original_command = "joseph"
elif command == "tiger":
original_command = "tiger"
elif command in untranslated:
original_command = command
else:
for original_command_name in raw_language["commands"].keys():
if raw_language["commands"][original_command_name] == command:
Expand Down Expand Up @@ -446,18 +443,22 @@ def check(r, u):
try:
if "twoMessages" in item:
if guild is not None:
if central.is_banned(str(guild.id)):
await channel.send("This server has been banned from using BibleBot.")
is_banned, reason = central.is_banned(str(guild.id))
if is_banned:
await channel.send("This server has been banned from using BibleBot. " +
"Reason: `" + reason + "`.")
await channel.send(
"If this is invalid, the server owner may appeal by contacting " +
"vypr#9944.")
"vypr#0001.")

central.log_message("err", shard, identifier, source, "Server is banned.")
return

if central.is_banned(str(sender.id)):
await channel.send(sender.mention + " You have been banned from using BibleBot.")
await channel.send("You may appeal by contacting vypr#9944.")
is_banned, reason = central.is_banned(str(sender.id))
if is_banned:
await channel.send(sender.mention + " You have been banned from using BibleBot. " +
"Reason: `" + reason + "`.")
await channel.send("You may appeal by contacting vypr#0001.")

central.log_message("err", shard, identifier, source, "User is banned.")
return
Expand All @@ -473,14 +474,14 @@ def check(r, u):
await channel.send("This server has been banned from using BibleBot.")
await channel.send(
"If this is invalid, the server owner may appeal by contacting " +
"vypr#9944.")
"vypr#0001.")

central.log_message("err", shard, identifier, source, "Server is banned.")
return

if central.is_banned(str(sender.id)):
await channel.send(sender.mention + " You have been banned from using BibleBot.")
await channel.send("You may appeal by contacting vypr#9944.")
await channel.send("You may appeal by contacting vypr#0001.")

central.log_message("err", shard, identifier, source, "User is banned.")
return
Expand Down
41 changes: 39 additions & 2 deletions src/central.py
Expand Up @@ -44,6 +44,7 @@
guildDB = tinydb.TinyDB(dir_path + "/../databases/guilddb")
versionDB = tinydb.TinyDB(dir_path + "/../databases/versiondb")
banDB = tinydb.TinyDB(dir_path + "/../databases/bandb")
optoutDB = tinydb.TinyDB(dir_path + "/../databases/optoutdb")

languages = languages

Expand Down Expand Up @@ -87,14 +88,14 @@ def log_message(level, shard, sender, source, msg):
logger.debug(message)


def add_ban(entryid):
def add_ban(entryid, reason):
ideal_entry = tinydb.Query()
result = banDB.search(ideal_entry.id == entryid)

if len(result) > 0:
return False
else:
banDB.insert({"id": entryid})
banDB.insert({"id": entryid, "reason": reason})
return True


Expand All @@ -113,6 +114,42 @@ def is_banned(entryid):
ideal_entry = tinydb.Query()
result = banDB.search(ideal_entry.id == entryid)

if len(result) > 0:
if "reason" in result[0].keys():
return True, result[0]["reason"]
else:
return False, None


def add_optout(entryid):
ideal_entry = tinydb.Query()
result = optoutDB.search(ideal_entry.id == entryid)

if len(result) > 0:
return False
else:
db.remove(ideal_entry.id == entryid)
guildDB.remove(ideal_entry.id == entryid)

optoutDB.insert({"id": entryid})
return True


def remove_optout(entryid):
ideal_entry = tinydb.Query()
result = optoutDB.search(ideal_entry.id == entryid)

if len(result) > 0:
optoutDB.remove(ideal_entry.id == entryid)
return True
else:
return False


def is_optout(entryid):
ideal_entry = tinydb.Query()
result = optoutDB.search(ideal_entry.id == entryid)

if len(result) > 0:
return True
else:
Expand Down
78 changes: 76 additions & 2 deletions src/handlers/commandlogic/commandbridge.py
Expand Up @@ -1277,12 +1277,18 @@ def run_owner_command(bot, command, args, lang):
"message": results
}
elif command == "ban":
ban_reason = ""

for index in range(0, len(args)):
if index != 0:
ban_reason += args[index] + " "

if central.is_snowflake(args[0]):
if central.add_ban(args[0]):
if central.add_ban(args[0], ban_reason[0:-1]):
return {
"level": "info",
"text": True,
"message": "Banned " + args[0] + "."
"message": "Banned " + args[0] + " for " + ban_reason[0:-1] + "."
}
else:
return {
Expand Down Expand Up @@ -1316,6 +1322,74 @@ def run_owner_command(bot, command, args, lang):
"text": True,
"message": "This is not an ID."
}
elif command == "reason":
if central.is_snowflake(args[0]):
is_banned, reason = central.is_banned(args[0])
if is_banned:
if reason is not None:
return {
"level": "info",
"text": True,
"message": args[0] + " is banned for `" + reason + "`."
}
else:
return {
"level": "info",
"text": True,
"message": args[0] + " is banned for an unknown reason."
}
else:
return {
"level": "err",
"text": True,
"message": args[0] + " is not banned."
}
else:
return {
"level": "err",
"text": True,
"message": "This is not an ID."
}
elif command == "optout":
if central.is_snowflake(args[0]):
if central.add_optout(args[0]):
return {
"level": "info",
"text": True,
"message": "Opt out " + args[0] + "."
}
else:
return {
"level": "err",
"text": True,
"message": args[0] + " is already opt out."
}
else:
return {
"level": "err",
"text": True,
"message": "This is not an ID."
}
elif command == "unoptout":
if central.is_snowflake(args[0]):
if central.remove_optout(args[0]):
return {
"level": "info",
"text": True,
"message": "Unoptout " + args[0] + "."
}
else:
return {
"level": "err",
"text": True,
"message": args[0] + " is not opt out."
}
else:
return {
"level": "err",
"text": True,
"message": "This is not an ID."
}
elif command == "leave":
if len(args) > 0:
exists = False
Expand Down

0 comments on commit 857b8f9

Please sign in to comment.