Merge branch 'master' of https://github.com/bobloy/Fox-V3
This commit is contained in:
commit
06bfb01fe3
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
.idea/
|
||||||
|
*.pyc
|
37
README.md
37
README.md
@ -1,19 +1,32 @@
|
|||||||
# Fox-V3
|
# Fox-V3
|
||||||
|
|
||||||
|
Cog Function
|
||||||
|
|
||||||
|
| Name | Status | Description
|
||||||
|
| --- | --- | --- |
|
||||||
|
| ccrole | **Beta** | Create custom commands that also assign roles |
|
||||||
|
| chatter | **Alpha** | Chat-bot trained to talk like your guild
|
||||||
|
| fight | **Incomplete** | Organize bracket tournaments within discord |
|
||||||
|
| flag | **Beta** | Create temporary marks on users that expire after specified time |
|
||||||
|
| hangman | **Incomplete** | Play a game of hangman |
|
||||||
|
| immortal | **Private** | Cog designed for a specific server, not recommended to install |
|
||||||
|
| leaver | **Incomplete** | Send a message in a channel when a user leaves the server |
|
||||||
|
| reactrestrict | **Alpha** | Removes reactions by role per channel |
|
||||||
|
| stealemoji | **Alpha** | Steals any custom emoji it sees |
|
||||||
|
| werewolf | **Incomplete** | Play the classic party game Werewolf within discord |
|
||||||
|
|
||||||
Cog Status
|
Cog Status Descriptions
|
||||||
|
|
||||||
- ccrole: **Incomplete** - Not yet ported to v3
|
- ccrole: May have some bugs, please create an issue if you find any
|
||||||
- challonge: **Incomplete** - Challonge integration with discord
|
- chatter: Missing some key features, but currently functional
|
||||||
- chatter: **Alpha** - Train your chat-bot to talk like your guild
|
- fight: Still in-progress, a massive project
|
||||||
- fight: **Incomplete** - Still in-progress, a massive project
|
- flag: Not yet ported to v3
|
||||||
- flag: **Incomplete** - Not yet ported to v3
|
- hangman: Not yet ported to v3
|
||||||
- hangman: **Incomplete** - Not yet ported to v3
|
- immortal: Designed for a specific server, not recommended to install
|
||||||
- immortal: **Private** - Designed for a specific server, not recommended to install
|
- leaver: Not yet ported to v3
|
||||||
- leaver: **Incomplete** - Not yet ported to v3
|
- reactrestrict: A bit clunky, but functional
|
||||||
- reactrestrict: **Beta** - Removes reactions by role per channel
|
- stealemoji: Some planned upgrades for server generation
|
||||||
- stealemoji: **Alpha** - Steals any custom emoji it sees
|
- werewolf: Another massive project, will be fully customizable
|
||||||
- werewolf: **Incomplete** - Play the classic party game Werewolf within discord
|
|
||||||
|
|
||||||
Many of these are functional in my V2 cogs at [Fox-Cogs v2](https://github.com/bobloy/Fox-Cogs)
|
Many of these are functional in my V2 cogs at [Fox-Cogs v2](https://github.com/bobloy/Fox-Cogs)
|
||||||
|
|
268
ccrole/ccrole.py
268
ccrole/ccrole.py
@ -3,10 +3,9 @@ import asyncio
|
|||||||
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from redbot.core import Config
|
from redbot.core import Config, checks
|
||||||
|
|
||||||
from .utils import checks
|
from redbot.core.utils.chat_formatting import pagify, box
|
||||||
from .utils.chat_formatting import pagify, box
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -19,224 +18,240 @@ class CCRole:
|
|||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.file_path = "data/ccrole/commands.json"
|
self.config = Config.get_conf(self, identifier=9999114111108101)
|
||||||
self.c_commands = dataIO.load_json(self.file_path)
|
default_guild = {
|
||||||
|
"cmdlist" : {},
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
|
|
||||||
@commands.group(pass_context=True, no_pm=True)
|
self.config.register_guild(**default_guild)
|
||||||
|
|
||||||
|
|
||||||
|
@commands.group(no_pm=True)
|
||||||
async def ccrole(self, ctx):
|
async def ccrole(self, ctx):
|
||||||
"""Custom commands management"""
|
"""Custom commands management"""
|
||||||
if ctx.invoked_subcommand is None:
|
if not ctx.invoked_subcommand:
|
||||||
await self.bot.send_cmd_help(ctx)
|
await ctx.send_help()
|
||||||
|
|
||||||
@ccrole.command(name="add", pass_context=True)
|
@ccrole.command(name="add")
|
||||||
@checks.mod_or_permissions(administrator=True)
|
@checks.mod_or_permissions(administrator=True)
|
||||||
async def ccrole_add(self, ctx, command : str):
|
async def ccrole_add(self, ctx, command : str):
|
||||||
"""Adds a custom command with roles"""
|
"""Adds a custom command with roles"""
|
||||||
command = command.lower()
|
command = command.lower()
|
||||||
if command in self.bot.commands:
|
if command in self.bot.all_commands:
|
||||||
await self.bot.say("That command is already a standard command.")
|
await ctx.send("That command is already a standard command.")
|
||||||
return
|
return
|
||||||
|
|
||||||
server = ctx.message.server
|
guild = ctx.guild
|
||||||
author = ctx.message.author
|
author = ctx.author
|
||||||
|
channel = ctx.channel
|
||||||
|
|
||||||
if server.id not in self.c_commands:
|
cmdlist = self.config.guild(ctx.guild).cmdlist
|
||||||
self.c_commands[server.id] = {}
|
|
||||||
cmdlist = self.c_commands[server.id]
|
if await cmdlist.get_raw(command, default=None):
|
||||||
if command in cmdlist:
|
await ctx.send("This command already exists. Delete it with `{}ccrole delete` first.".format(ctx.prefix))
|
||||||
await self.bot.say("This command already exists. Delete"
|
|
||||||
"`it with {}ccrole delete` first."
|
|
||||||
"".format(ctx.prefix))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Roles to add
|
# Roles to add
|
||||||
await self.bot.say('What roles should it add? (Must be comma separated)\nSay `None` to skip adding roles')
|
await ctx.send('What roles should it add? (Must be **comma separated**)\nSay `None` to skip adding roles')
|
||||||
|
|
||||||
answer = await self.bot.wait_for_message(timeout=120, author=author)
|
def check(m):
|
||||||
if not answer:
|
return m.author == author and m.channel==channel
|
||||||
await self.bot.say("Timed out, canceling")
|
|
||||||
return
|
|
||||||
arole_list = []
|
|
||||||
if answer.content.upper()!="NONE":
|
|
||||||
arole_list = answer.content.split(",")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
arole_list = [discord.utils.get(server.roles, name=role.strip(' ')).id for role in arole_list]
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
||||||
except:
|
except asyncio.TimeoutError:
|
||||||
await self.bot.say("Invalid answer, canceling")
|
await ctx.send("Timed out, canceling")
|
||||||
|
|
||||||
|
arole_list = []
|
||||||
|
if answer.content.upper()!="NONE":
|
||||||
|
arole_list = await self._get_roles_from_content(ctx, answer.content)
|
||||||
|
if arole_list is None:
|
||||||
|
await ctx.send("Invalid answer, canceling")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Roles to remove
|
# Roles to remove
|
||||||
await self.bot.say('What roles should it remove? (Must be comma separated)\nSay `None` to skip removing roles')
|
await ctx.send('What roles should it remove? (Must be comma separated)\nSay `None` to skip removing roles')
|
||||||
|
try:
|
||||||
answer = await self.bot.wait_for_message(timeout=120, author=author)
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
||||||
if not answer:
|
except asyncio.TimeoutError:
|
||||||
await self.bot.say("Timed out, canceling")
|
await ctx.send("Timed out, canceling")
|
||||||
return
|
|
||||||
|
|
||||||
rrole_list = []
|
rrole_list = []
|
||||||
if answer.content.upper()!="NONE":
|
if answer.content.upper()!="NONE":
|
||||||
rrole_list = answer.content.split(",")
|
rrole_list = await self._get_roles_from_content(ctx, answer.content)
|
||||||
|
if rrole_list is None:
|
||||||
try:
|
await ctx.send("Invalid answer, canceling")
|
||||||
rrole_list = [discord.utils.get(server.roles, name=role.strip(' ')).id for role in rrole_list]
|
|
||||||
except:
|
|
||||||
await self.bot.say("Invalid answer, canceling")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Roles to use
|
# Roles to use
|
||||||
await self.bot.say('What roles are allowed to use this command? (Must be comma separated)\nSay `None` to allow all roles')
|
await ctx.send('What roles are allowed to use this command? (Must be comma separated)\nSay `None` to allow all roles')
|
||||||
|
|
||||||
answer = await self.bot.wait_for_message(timeout=120, author=author)
|
try:
|
||||||
if not answer:
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
||||||
await self.bot.say("Timed out, canceling")
|
except asyncio.TimeoutError:
|
||||||
return
|
await ctx.send("Timed out, canceling")
|
||||||
|
|
||||||
prole_list = []
|
prole_list = []
|
||||||
if answer.content.upper()!="NONE":
|
if answer.content.upper()!="NONE":
|
||||||
prole_list = answer.content.split(",")
|
prole_list = await self._get_roles_from_content(ctx, answer.content)
|
||||||
|
if prole_list is None:
|
||||||
try:
|
await ctx.send("Invalid answer, canceling")
|
||||||
prole_list = [discord.utils.get(server.roles, name=role.strip(' ')).id for role in prole_list]
|
|
||||||
except:
|
|
||||||
await self.bot.say("Invalid answer, canceling")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Selfrole
|
# Selfrole
|
||||||
await self.bot.say('Is this a targeted command?(yes/no)\nNo will make this a selfrole command')
|
await ctx.send('Is this a targeted command?(yes/no)\nNo will make this a selfrole command')
|
||||||
|
|
||||||
answer = await self.bot.wait_for_message(timeout=120, author=author)
|
try:
|
||||||
if not answer:
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
||||||
await self.bot.say("Timed out, canceling")
|
except asyncio.TimeoutError:
|
||||||
return
|
await ctx.send("Timed out, canceling")
|
||||||
|
|
||||||
if answer.content.upper() in ["Y", "YES"]:
|
if answer.content.upper() in ["Y", "YES"]:
|
||||||
targeted = True
|
targeted = True
|
||||||
await self.bot.say("This command will be targeted")
|
await ctx.send("This command will be **`targeted`**")
|
||||||
else:
|
else:
|
||||||
targeted = False
|
targeted = False
|
||||||
await self.bot.say("This command will be selfrole")
|
await ctx.send("This command will be **`selfrole`**")
|
||||||
|
|
||||||
# Message to send
|
# Message to send
|
||||||
await self.bot.say('What message should the bot send?\nSay `None` to send the default `Success!` message')
|
await ctx.send('What message should the bot say when using this command?\nSay `None` to send the default `Success!` message')
|
||||||
|
|
||||||
answer = await self.bot.wait_for_message(timeout=120, author=author)
|
try:
|
||||||
if not answer:
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
||||||
await self.bot.say("Timed out, canceling")
|
except asyncio.TimeoutError:
|
||||||
return
|
await ctx.send("Timed out, canceling")
|
||||||
text = "Success!"
|
text = "Success!"
|
||||||
if answer.content.upper()!="NONE":
|
if answer.content.upper()!="NONE":
|
||||||
text = answer.content
|
text = answer.content
|
||||||
|
|
||||||
# Save the command
|
# Save the command
|
||||||
|
|
||||||
cmdlist[command] = {'text': text, 'aroles': arole_list, 'rroles': rrole_list, "proles": prole_list, "targeted": targeted}
|
out = {'text': text, 'aroles': arole_list, 'rroles': rrole_list, "proles": prole_list, "targeted": targeted}
|
||||||
|
|
||||||
self.c_commands[server.id] = cmdlist
|
await cmdlist.set_raw(command, value=out)
|
||||||
dataIO.save_json(self.file_path, self.c_commands)
|
|
||||||
await self.bot.say("Custom command successfully added.")
|
|
||||||
|
|
||||||
@ccrole.command(name="delete", pass_context=True)
|
ctx.send("Custom Command **`{}`** successfully added".format(command))
|
||||||
|
|
||||||
|
@ccrole.command(name="delete")
|
||||||
@checks.mod_or_permissions(administrator=True)
|
@checks.mod_or_permissions(administrator=True)
|
||||||
async def ccrole_delete(self, ctx, command : str):
|
async def ccrole_delete(self, ctx, command : str):
|
||||||
"""Deletes a custom command
|
"""Deletes a custom command
|
||||||
Example:
|
Example:
|
||||||
[p]ccrole delete yourcommand"""
|
[p]ccrole delete yourcommand"""
|
||||||
server = ctx.message.server
|
guild = ctx.guild
|
||||||
command = command.lower()
|
command = command.lower()
|
||||||
if server.id in self.c_commands:
|
if not await self.config.guild(ctx.guild).cmdlist.get_raw(command, default=None):
|
||||||
cmdlist = self.c_commands[server.id]
|
await ctx.send("That command doesn't exist")
|
||||||
if command in cmdlist:
|
|
||||||
cmdlist.pop(command, None)
|
|
||||||
self.c_commands[server.id] = cmdlist
|
|
||||||
dataIO.save_json(self.file_path, self.c_commands)
|
|
||||||
await self.bot.say("Custom command successfully deleted.")
|
|
||||||
else:
|
else:
|
||||||
await self.bot.say("That command doesn't exist.")
|
await self.config.guild(ctx.guild).cmdlist.set_raw(command, value=None)
|
||||||
else:
|
await ctx.send("Custom command successfully deleted.")
|
||||||
await self.bot.say("There are no custom commands in this server."
|
|
||||||
" Use `{}ccrole add` to start adding some."
|
|
||||||
"".format(ctx.prefix))
|
|
||||||
|
|
||||||
@ccrole.command(name="list", pass_context=True)
|
@ccrole.command(name="list")
|
||||||
async def ccrole_list(self, ctx):
|
async def ccrole_list(self, ctx):
|
||||||
"""Shows custom commands list"""
|
"""Shows custom commands list"""
|
||||||
server = ctx.message.server
|
guild = ctx.guild
|
||||||
commands = self.c_commands.get(server.id, {})
|
commands = await self.config.guild(ctx.guild).cmdlist()
|
||||||
|
|
||||||
if not commands:
|
if not commands:
|
||||||
await self.bot.say("There are no custom commands in this server."
|
await ctx.send("There are no custom commands in this server. Use `{}ccrole add` to start adding some.".format(ctx.prefix))
|
||||||
" Use `{}ccrole add` to start adding some."
|
|
||||||
"".format(ctx.prefix))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
commands = ", ".join([ctx.prefix + c for c in sorted(commands.keys())])
|
commands = ", ".join([ctx.prefix + c for c in sorted(commands.keys())])
|
||||||
commands = "Custom commands:\n\n" + commands
|
commands = "Custom commands:\n\n" + commands
|
||||||
|
|
||||||
if len(commands) < 1500:
|
if len(commands) < 1500:
|
||||||
await self.bot.say(box(commands))
|
await ctx.send(box(commands))
|
||||||
else:
|
else:
|
||||||
for page in pagify(commands, delims=[" ", "\n"]):
|
for page in pagify(commands, delims=[" ", "\n"]):
|
||||||
await self.bot.whisper(box(page))
|
await ctx.author.send(box(page))
|
||||||
|
await ctx.send("Command list DM'd")
|
||||||
|
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
if len(message.content) < 2 or message.channel.is_private:
|
if len(message.content) < 2 or message.guild is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
server = message.server
|
guild = message.guild
|
||||||
prefix = self.get_prefix(message)
|
try:
|
||||||
|
prefix = await self.get_prefix(message)
|
||||||
if not prefix:
|
except ValueError:
|
||||||
return
|
return
|
||||||
|
|
||||||
if server.id in self.c_commands and self.bot.user_allowed(message):
|
|
||||||
cmdlist = self.c_commands[server.id]
|
cmdlist = self.config.guild(guild).cmdlist
|
||||||
cmd = message.content[len(prefix):].split()[0]
|
cmd = message.content[len(prefix):].split()[0]
|
||||||
if cmd in cmdlist:
|
cmd = await cmdlist.get_raw(cmd.lower(), default=None)
|
||||||
cmd = cmdlist[cmd]
|
|
||||||
await self.eval_cc(cmd, message)
|
if cmd:
|
||||||
elif cmd.lower() in cmdlist:
|
|
||||||
cmd = cmdlist[cmd.lower()]
|
|
||||||
await self.eval_cc(cmd, message)
|
await self.eval_cc(cmd, message)
|
||||||
|
|
||||||
def get_prefix(self, message):
|
async def _get_roles_from_content(self, ctx, content):
|
||||||
for p in self.bot.settings.get_prefixes(message.server):
|
content_list = content.split(",")
|
||||||
if message.content.startswith(p):
|
role_list = []
|
||||||
|
try:
|
||||||
|
role_list = [discord.utils.get(ctx.guild.roles, name=role.strip(' ')).id for role in content_list]
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return role_list
|
||||||
|
|
||||||
|
async def get_prefix(self, message: discord.Message) -> str:
|
||||||
|
"""
|
||||||
|
Borrowed from alias cog
|
||||||
|
Tries to determine what prefix is used in a message object.
|
||||||
|
Looks to identify from longest prefix to smallest.
|
||||||
|
|
||||||
|
Will raise ValueError if no prefix is found.
|
||||||
|
:param message: Message object
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
content = message.content
|
||||||
|
prefix_list = await self.bot.command_prefix(self.bot, message)
|
||||||
|
prefixes = sorted(prefix_list,
|
||||||
|
key=lambda pfx: len(pfx),
|
||||||
|
reverse=True)
|
||||||
|
for p in prefixes:
|
||||||
|
if content.startswith(p):
|
||||||
return p
|
return p
|
||||||
return False
|
raise ValueError
|
||||||
|
|
||||||
async def eval_cc(self, cmd, message):
|
async def eval_cc(self, cmd, message):
|
||||||
|
"""Does all the work"""
|
||||||
if cmd['proles'] and not (set(role.id for role in message.author.roles) & set(cmd['proles'])):
|
if cmd['proles'] and not (set(role.id for role in message.author.roles) & set(cmd['proles'])):
|
||||||
return # Not authorized, do nothing
|
return # Not authorized, do nothing
|
||||||
|
|
||||||
if cmd['targeted']:
|
if cmd['targeted']:
|
||||||
try:
|
try:
|
||||||
target = discord.utils.get(message.server.members, mention=message.content.split()[1])
|
target = discord.utils.get(message.guild.members, mention=message.content.split()[1])
|
||||||
except:
|
except:
|
||||||
target = None
|
target = None
|
||||||
|
|
||||||
if not target:
|
if not target:
|
||||||
out_message = "This command is targeted! @mention a target\n`{} <target>`".format(message.content.split()[0])
|
out_message = "This command is targeted! @mention a target\n`{} <target>`".format(message.content.split()[0])
|
||||||
|
|
||||||
await self.bot.send_message(message.channel, out_message)
|
await message.channel.send(out_message)
|
||||||
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target = message.author
|
target = message.author
|
||||||
|
|
||||||
if cmd['aroles']:
|
if cmd['aroles']:
|
||||||
arole_list = [discord.utils.get(message.server.roles, id=roleid) for roleid in cmd['aroles']]
|
arole_list = [discord.utils.get(message.guild.roles, id=roleid) for roleid in cmd['aroles']]
|
||||||
# await self.bot.send_message(message.channel, "Adding: "+str([str(arole) for arole in arole_list]))
|
# await self.bot.send_message(message.channel, "Adding: "+str([str(arole) for arole in arole_list]))
|
||||||
await self.bot.add_roles(target, *arole_list)
|
try:
|
||||||
|
await target.add_roles(*arole_list)
|
||||||
|
except discord.Forbidden:
|
||||||
|
await message.channel.send("Permission error: Unable to add roles")
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
if cmd['rroles']:
|
if cmd['rroles']:
|
||||||
rrole_list = [discord.utils.get(message.server.roles, id=roleid) for roleid in cmd['rroles']]
|
rrole_list = [discord.utils.get(message.guild.roles, id=roleid) for roleid in cmd['rroles']]
|
||||||
# await self.bot.send_message(message.channel, "Removing: "+str([str(rrole) for rrole in rrole_list]))
|
# await self.bot.send_message(message.channel, "Removing: "+str([str(rrole) for rrole in rrole_list]))
|
||||||
await self.bot.remove_roles(target, *rrole_list)
|
try:
|
||||||
|
await target.remove_roles(*rrole_list)
|
||||||
await self.bot.send_message(message.channel, cmd['text'])
|
except discord.Forbidden:
|
||||||
|
await message.channel.send("Permission error: Unable to remove roles")
|
||||||
|
await message.channel.send(cmd['text'])
|
||||||
|
|
||||||
# {'text': text, 'aroles': arole_list, 'rroles': rrole_list, "proles", prole_list, "targeted": targeted}
|
# {'text': text, 'aroles': arole_list, 'rroles': rrole_list, "proles", prole_list, "targeted": targeted}
|
||||||
|
|
||||||
@ -270,22 +285,3 @@ class CCRole:
|
|||||||
# else:
|
# else:
|
||||||
# return raw_result
|
# return raw_result
|
||||||
# return str(getattr(first, second, raw_result))
|
# return str(getattr(first, second, raw_result))
|
||||||
|
|
||||||
|
|
||||||
def check_folders():
|
|
||||||
if not os.path.exists("data/ccrole"):
|
|
||||||
print("Creating data/ccrole folder...")
|
|
||||||
os.makedirs("data/ccrole")
|
|
||||||
|
|
||||||
|
|
||||||
def check_files():
|
|
||||||
f = "data/ccrole/commands.json"
|
|
||||||
if not dataIO.is_valid_json(f):
|
|
||||||
print("Creating empty commands.json...")
|
|
||||||
dataIO.save_json(f, {})
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
|
||||||
check_folders()
|
|
||||||
check_files()
|
|
||||||
bot.add_cog(CCRole(bot))
|
|
@ -1,5 +0,0 @@
|
|||||||
from .challonge import Challonge
|
|
||||||
|
|
||||||
def setup(bot):
|
|
||||||
n = Challonge(bot)
|
|
||||||
bot.add_cog(n)
|
|
@ -1,134 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
import challonge
|
|
||||||
|
|
||||||
import discord
|
|
||||||
from discord.ext import commands
|
|
||||||
|
|
||||||
from redbot.core.utils.chat_formatting import pagify
|
|
||||||
from redbot.core.utils.chat_formatting import box
|
|
||||||
from redbot.core import Config
|
|
||||||
from redbot.core import checks
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Challonge:
|
|
||||||
"""Cog for organizing Challonge tourneys"""
|
|
||||||
|
|
||||||
def __init__(self, bot):
|
|
||||||
self.bot = bot
|
|
||||||
self.config = Config.get_conf(self, identifier=6710497108108111110103101)
|
|
||||||
default_global = {
|
|
||||||
"username": None,
|
|
||||||
"apikey": None
|
|
||||||
}
|
|
||||||
default_guild = {
|
|
||||||
"reportchannel": None,
|
|
||||||
"announcechannel": None
|
|
||||||
}
|
|
||||||
|
|
||||||
self.config.register_global(**default_global)
|
|
||||||
self.config.register_guild(**default_guild)
|
|
||||||
|
|
||||||
await self._set_credentials()
|
|
||||||
|
|
||||||
# ************************Challonge command group start************************
|
|
||||||
|
|
||||||
@commands.group()
|
|
||||||
@commands.guild_only()
|
|
||||||
async def challonge(self, ctx):
|
|
||||||
"""Challonge command base"""
|
|
||||||
if ctx.invoked_subcommand is None:
|
|
||||||
await ctx.send_help()
|
|
||||||
# await ctx.send("I can do stuff!")
|
|
||||||
|
|
||||||
|
|
||||||
@challonge.command(name="apikey")
|
|
||||||
async def c_apikey(self, ctx, username, apikey):
|
|
||||||
"""Sets challonge username and apikey"""
|
|
||||||
await self.config.username.set(username)
|
|
||||||
await self.config.apikey.set(apikey)
|
|
||||||
await self._set_credentials()
|
|
||||||
await ctx.send("Success!")
|
|
||||||
|
|
||||||
@challonge.command(name="report")
|
|
||||||
async def c_report(self, ctx, channel: discord.TextChannel=None):
|
|
||||||
"""Set the channel for self-reporting matches"""
|
|
||||||
if channel is None:
|
|
||||||
channel = ctx.channel
|
|
||||||
|
|
||||||
await self.config.guild(ctx.guild).reportchnnl.set(channel.id)
|
|
||||||
|
|
||||||
channel = (await self._get_reportchnnl(ctx.guild))
|
|
||||||
await ctx.send("Self-Reporting Channel is now set to: " + channel.mention)
|
|
||||||
|
|
||||||
@challonge.command(name="announce")
|
|
||||||
async def c_announce(self, ctx, channel: discord.TextChannel=None):
|
|
||||||
"""Set the channel for tournament announcements"""
|
|
||||||
if channel is None:
|
|
||||||
channel = ctx.channel
|
|
||||||
|
|
||||||
await self.config.guild(ctx.guild).announcechnnl.set(channel.id)
|
|
||||||
|
|
||||||
channel = (await self._get_announcechnnl(ctx.guild))
|
|
||||||
await ctx.send("Announcement Channel is now set to: " + channel.mention)
|
|
||||||
|
|
||||||
# ************************Private command group start************************
|
|
||||||
async def _print_tourney(self, guild: discord.Guild, tID: int):
|
|
||||||
channel = (await self._get_announcechnnl(ctx.guild))
|
|
||||||
|
|
||||||
await channel.send()
|
|
||||||
|
|
||||||
async def _set_credentials(self):
|
|
||||||
username = await self.config.username
|
|
||||||
apikey = await self.config.apikey
|
|
||||||
if username and apikey:
|
|
||||||
challonge.set_credentials(username, apikey)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def _get_message_from_id(self, guild: discord.Guild, message_id: int):
|
|
||||||
"""
|
|
||||||
Tries to find a message by ID in the current guild context.
|
|
||||||
:param ctx:
|
|
||||||
:param message_id:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
for channel in guild.text_channels:
|
|
||||||
try:
|
|
||||||
return await channel.get_message(message_id)
|
|
||||||
except discord.NotFound:
|
|
||||||
pass
|
|
||||||
except AttributeError: # VoiceChannel object has no attribute 'get_message'
|
|
||||||
pass
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
async def _get_announcechnnl(self, guild: discord.Guild):
|
|
||||||
channelid = await self.config.guild(guild).announcechnnl()
|
|
||||||
channel = self._get_channel_from_id(channelid)
|
|
||||||
return channel
|
|
||||||
|
|
||||||
async def _get_reportchnnl(self, guild: discord.Guild):
|
|
||||||
channelid = await self.config.guild(guild).reportchnnl()
|
|
||||||
channel = self._get_channel_from_id(channelid)
|
|
||||||
return channel
|
|
||||||
|
|
||||||
def _get_channel_from_id(self, channelid):
|
|
||||||
return self.bot.get_channel(channelid)
|
|
||||||
|
|
||||||
def _get_user_from_id(self, userid):
|
|
||||||
# guild = self._get_guild_from_id(guildID)
|
|
||||||
# return discord.utils.get(guild.members, id=userid)
|
|
||||||
return self.bot.get_user(userid)
|
|
||||||
|
|
||||||
def _get_guild_from_id(self, guildID):
|
|
||||||
return self.bot.get_guild(guildID)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"author" : ["Bobloy"],
|
|
||||||
"bot_version" : [3,0,0],
|
|
||||||
"description" : "[Incomplete] Cog to organize tournaments within Discord using Challonge",
|
|
||||||
"hidden" : false,
|
|
||||||
"install_msg" : "Thank you for installing the Challonge Cog.",
|
|
||||||
"requirements" : ["iso8601", "challonge"],
|
|
||||||
"short" : "[Incomplete] Cog to organize Challonge tournaments",
|
|
||||||
"tags" : ["game", "fun", "fight", "tournament", "tourney", "challonge", "elimination", "bracket", "bobloy"]
|
|
||||||
}
|
|
@ -2,7 +2,6 @@ import asyncio
|
|||||||
import discord
|
import discord
|
||||||
|
|
||||||
# Import all roles here
|
# Import all roles here
|
||||||
from werewolf.role import Role
|
|
||||||
from werewolf.roles.vanillawerewolf import VanillaWerewolf
|
from werewolf.roles.vanillawerewolf import VanillaWerewolf
|
||||||
from werewolf.roles.villager import Villager
|
from werewolf.roles.villager import Villager
|
||||||
from werewolf.roles.seer import Seer
|
from werewolf.roles.seer import Seer
|
||||||
@ -10,39 +9,44 @@ from werewolf.roles.seer import Seer
|
|||||||
# All roles in this list for iterating
|
# All roles in this list for iterating
|
||||||
role_list = [Villager, VanillaWerewolf]
|
role_list = [Villager, VanillaWerewolf]
|
||||||
|
|
||||||
#Example code:
|
"""
|
||||||
# 0 = Villager
|
Example code:
|
||||||
# 1 = VanillaWerewolf
|
0 = Villager
|
||||||
# E1 = Random Town
|
1 = VanillaWerewolf
|
||||||
# R1 = Random Werewolf
|
E1 = Random Town
|
||||||
# J1 = Benign Neutral
|
R1 = Random Werewolf
|
||||||
|
J1 = Benign Neutral
|
||||||
|
|
||||||
# 0001-1112E11R112P2
|
0001-1112E11R112P2
|
||||||
# 0,0,0,1,11,12,E1,R1,R1,R1,R2,P2
|
0,0,0,1,11,12,E1,R1,R1,R1,R2,P2
|
||||||
|
|
||||||
|
pre-letter = exact role position
|
||||||
|
double digit position preempted by `-`
|
||||||
|
"""
|
||||||
|
|
||||||
# pre-letter = exact role position
|
|
||||||
# double digit position pre-empted by `-`
|
|
||||||
|
|
||||||
async def parse_code(code):
|
async def parse_code(code):
|
||||||
|
"""Do the magic described above"""
|
||||||
out = []
|
out = []
|
||||||
#Do the magic described above
|
|
||||||
decode = code.copy() # for now, pass exact names
|
decode = code.copy() # for now, pass exact names
|
||||||
for role_id in decode:
|
for role_id in decode:
|
||||||
print(role_id)
|
print(role_id)
|
||||||
if role_id == "Villager":
|
if role_id == "Villager":
|
||||||
role = Villager
|
role = Villager
|
||||||
if role_id == "VanillaWerewolf":
|
elif role_id == "VanillaWerewolf":
|
||||||
role = VanillaWerewolf
|
role = VanillaWerewolf
|
||||||
if role_id == "Seer":
|
elif role_id == "Seer":
|
||||||
role = Seer
|
role = Seer
|
||||||
|
else: # Fail to parse
|
||||||
|
return None
|
||||||
out.append(role)
|
out.append(role)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
async def build_game(channel: discord.TextChannel):
|
async def build_game(channel: discord.TextChannel):
|
||||||
await channel.send("Not currently available")
|
await channel.send("Not currently available")
|
||||||
|
|
||||||
|
|
||||||
code = 12345678
|
code = 12345678
|
||||||
|
|
||||||
await channel.send("Your game code is **`{}`**".format(code))
|
await channel.send("Your game code is **`{}`**".format(code))
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from werewolf.player import Player
|
from werewolf.player import Player
|
||||||
@ -60,9 +58,6 @@ class Game:
|
|||||||
|
|
||||||
self.night_results = []
|
self.night_results = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
async def setup(self, ctx):
|
async def setup(self, ctx):
|
||||||
@ -91,7 +86,8 @@ class Game:
|
|||||||
self.guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True)
|
self.guild.me: discord.PermissionOverwrite(read_messages=True, send_messages=True)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.channel_category = await self.guild.create_category("ww-game", overwrites=overwrite, reason="New game of werewolf")
|
self.channel_category = await self.guild.create_category("ww-game", overwrites=overwrite, reason="New game of "
|
||||||
|
"werewolf")
|
||||||
|
|
||||||
for player in self.players:
|
for player in self.players:
|
||||||
overwrite[player.member] = discord.PermissionOverwrite(read_messages=True)
|
overwrite[player.member] = discord.PermissionOverwrite(read_messages=True)
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
"""
|
"""
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
class Role:
|
class Role:
|
||||||
"""
|
"""
|
||||||
Base Role class for werewolf game
|
Base Role class for werewolf game
|
||||||
|
@ -97,12 +97,12 @@ class Seer(Role):
|
|||||||
# async def _at_day_end(self):
|
# async def _at_day_end(self):
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
async def _at_night_start(self):
|
async def _at_night_start(self, data=None):
|
||||||
await self.game.generate_targets(self.player.member)
|
await self.game.generate_targets(self.player.member)
|
||||||
await self.player.send_dm("{}\n**Pick a target to see tonight**\n")
|
await self.player.send_dm("{}\n**Pick a target to see tonight**\n")
|
||||||
|
|
||||||
|
|
||||||
async def _at_night_end(self):
|
async def _at_night_end(self, data=None):
|
||||||
target = await self.game.visit(self.see_target)
|
target = await self.game.visit(self.see_target)
|
||||||
|
|
||||||
alignment = None
|
alignment = None
|
||||||
|
@ -5,8 +5,6 @@ from discord.ext import commands
|
|||||||
|
|
||||||
from redbot.core import Config
|
from redbot.core import Config
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
|
|
||||||
from werewolf.game import Game
|
from werewolf.game import Game
|
||||||
|
|
||||||
|
|
||||||
@ -49,7 +47,6 @@ class Werewolf:
|
|||||||
else:
|
else:
|
||||||
await ctx.send("New game has started")
|
await ctx.send("New game has started")
|
||||||
|
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ww.command()
|
@ww.command()
|
||||||
async def join(self, ctx):
|
async def join(self, ctx):
|
||||||
@ -157,7 +154,7 @@ class Werewolf:
|
|||||||
# If multiple games, panic
|
# If multiple games, panic
|
||||||
for game in self.games.values():
|
for game in self.games.values():
|
||||||
if await game.get_player_by_member(ctx.author):
|
if await game.get_player_by_member(ctx.author):
|
||||||
break #game = game
|
break # game = game
|
||||||
else:
|
else:
|
||||||
await ctx.send("You're not part of any werewolf game")
|
await ctx.send("You're not part of any werewolf game")
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user