Skip to content

Orb command #124

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from bot.cogs.theinherentlyindescribablenatureoftheuniverse import Theinherentlyindescribablenatureoftheuniverse # noqa E501
from bot.cogs.tiles import Tiles
from bot.cogs.wiki import Wiki
from bot.cogs.orb import Orb

from bot.shared import config

Expand Down Expand Up @@ -76,6 +77,7 @@ async def on_command_error(ctx, error):
bot.add_cog(Theinherentlyindescribablenatureoftheuniverse(bot))
bot.add_cog(Tiles(bot))
bot.add_cog(Wiki(bot))
bot.add_cog(Orb(bot))
bot.run(config['Discord token'])


Expand Down
97 changes: 97 additions & 0 deletions bot/cogs/orb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import logging
import re
import random
import asyncio

import discord
from discord.ext.commands import Cog, Bot
from discord.message import Message
from bot.shared import config
from discord import DeletedReferencedMessage


log = logging.getLogger('bot.' + __name__)

orb_command = re.compile(r"(^\w?\^\w?orb)", re.IGNORECASE)
orbs = [
'🔴',
'🟠',
'🟡',
'🟢',
'🔵',
'🟣',
'🟤',
'⚫',
'⚪',
'🌕',
'🪩',
'🫧',
'🔮',
'🎱',
'<:orb:1357170327657906307>',
'<:baetyl:957116466673618994>'
]
strange_orbs = [
'🥎',
'⚽',
'🏀',
'🧋',
'🧶',
'🪀',
'💿'
]
confirm_text = ["Launching orbs!",
"Initiating orb strategy mode.",
"With the power of every server member!",
"Orbs."]


class Orb(Cog):
"""Initiate Orb Strategy.

Usage: Reply to a message with '^orb this fool'
other usages:
^orbify
^orb this delver, ex."""
def __init__(self, bot: Bot):
self.bot = bot
self.config = config['Orb']

@Cog.listener()
async def on_message(self, msg: Message):
if msg.author.id in self.config['ignore'] or msg.author == self.bot.user:
return # ignore ignored users and bots
if msg.reference is None:
return
if not orb_command.match(msg.content):
return
# Grab only replies. Or at least, as best it can with this
# version of discord.py.
msg_ref = msg.reference
if (not msg_ref.resolved or
type(msg_ref.resolved) is DeletedReferencedMessage):

log.info(f'({msg.channel}) <{msg.author}> tried to orb someone but was unsuccessful.')
msg.channel.send(
"I couldn't see the msg you replied to, sorry.")
if msg_ref.message_id:
# Grab message the reply was for.
replied_msg = await msg.channel.fetch_message(msg_ref.message_id)
if replied_msg.author.id == msg.author.id:
# You can't orb yourself
return # change to pass for lonely testers
log.info(f'({msg.channel}) <{msg.author}> orbed {replied_msg.author}')
# Shuffle order of orb, and add in a few Strange Orb
random_orbs = random.sample(orbs, k=16)
for strange_orb in random.sample(strange_orbs,
k=random.randrange(1, 3)):
random_orbs.insert(random.randrange(0, len(random_orbs)),
strange_orb)
# Orb this fool!
msg.channel.send(confirm_text[random.randrange(0, 4)])
for orb in random_orbs:
try:
await replied_msg.add_reaction(orb)
except discord.errors.HTTPException as e:
print(f"Error when trying to grab emoji {orb}:{e.text}")
await asyncio.sleep(0.5)
50 changes: 29 additions & 21 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ Log folder: logs
# Game installation to read from:
Qud install folder: C:\Steam\steamapps\common\Caves of Qud


#############################
# Configs for individual cogs
#############################
Bugs:
channels: [ # Channels to listen for bug reacts in:
449667247297003520, # #bugs
459482205635215360, # #beta-bugs
449312747683971072, # #modding
]
allowed roles: [ # Roles that can open a new issue via react:
443578758629425152, # Sultan
447173558330982400, # Mayor
579024675598761995, # Tinker
707378307649241210, # Bug Herder
]
channels: # Channels to listen for bug reacts in:
[
449667247297003520, # #bugs
459482205635215360, # #beta-bugs
449312747683971072, # #modding
]
allowed roles: # Roles that can open a new issue via react:
[
443578758629425152, # Sultan
447173558330982400, # Mayor
579024675598761995, # Tinker
707378307649241210, # Bug Herder
]
trigger: 🐛
success reaction: ☑
fail reaction: ⚠️
Expand All @@ -31,16 +32,18 @@ Bugs:
bot password: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Decode:
channels: [ # Channels to listen for character build codes in:
449342897788026882, # #character-builds
571405896597635073, # #build-club
716755952967352420, # #bot-spam
482714670860468234, # #trash-divining
]
channels: # Channels to listen for character build codes in:
[
449342897788026882, # #character-builds
571405896597635073, # #build-club
716755952967352420, # #bot-spam
482714670860468234, # #trash-divining
]
# ignoring bots should be redundant, but specify anyway
ignore: [ # Users to ignore:
502293569764327444, # Cryptogull
]
ignore: # Users to ignore:
[
502293569764327444, # Cryptogull
]

Reddit:
client ID: xxxxxxxxxxxxxx
Expand All @@ -61,3 +64,8 @@ Wiki:
site: wiki.cavesofqud.com
basic search limit: 10
fulltext search limit: 5

Orb:
ignore: [
502293569764327444, # Cryptogull
]