def c4_play(self, ctx, *, user: discord.Member=None):
"""Star a game of Connect Four
`[p]c4 start @user` will start a game
with that user in the current channel."""
if not self.chan_check(ctx):
return
if user:
session = self.session(ctx)
if session:
await self.message(ctx, msg="There is already an active game in this channel.", level=2)
elif user.id == ctx.author.id:
await self.message(ctx, msg="You cannot start a game with yourself.", level=1)
elif user.id == self.bot.user.id:
await self.message(ctx, msg="NOT IMPLEMENTED: You can play against SESTREN soon."
"<:doritoface:337530039677485057>", level=1)
# self.sessions[ctx.channel.id] = ConnectFourSession(user, ctx)
# await self.send_board(ctx, init=True)
# self.sessions[ctx.channel.id].s_play()
# await self.send_board(ctx)
else:
self.sessions[ctx.channel.id] = ConnectFourSession(user, ctx)
await self.send_board(ctx, init=True)
else:
await self.bot.formatter.format_help_for(ctx, ctx.command, "You need another player to start.")
python类Member()的实例源码
def discrim(self, ctx, *, member: discord.Member=None):
"""Finds a username that you can use to change discriminator
[p]discrim"""
if not member:
member = ctx.author
d = member.discriminator
f = discord.utils.find(lambda x: x.discriminator == d and not x.id == member.id,
self.bot.get_all_members())
if f is not None:
em = discord.Embed(title="Discrim",
description="Change your name to `{}` and then back to `{}` to get a new discriminator"
"".format(f.name, member.name), colour=0x00FF00)
await ctx.send(embed=em)
else:
em = discord.Embed(title="Sorry",
description="I couldn't find another person with your discriminator", colour=0xFF0000)
await ctx.send(embed=em)
def mute(self, ctx, *, user:discord.Member):
"""Mute un utilisateur
Requiert la permission de kick"""
await self.bot.delete_message(ctx.message)
if ctx.message.author.server_permissions.kick_members == True:
overwrite = ctx.message.channel.overwrites_for(user) or discord.PermissionOverwrite()
overwrite.send_messages = False
await self.bot.edit_channel_permissions(ctx.message.channel, user, overwrite)
tmp = await self.bot.send_message(ctx.message.channel, "{} is now muted here !".format(user.mention))
await asyncio.sleep(5)
await self.bot.delete_message(tmp)
else:
tmp = await self.bot.say("```\nVous n'avez pas la permission d'utiliser cette commande\n```")
await asyncio.sleep(5)
await self.bot.delete_message(tmp)
def unmute(self, ctx, *, user:discord.Member):
"""Unute un utilisateur
Requiert la permission de kick"""
await self.bot.delete_message(ctx.message)
if ctx.message.author.server_permissions.kick_members == True:
overwrite = ctx.message.channel.overwrites_for(user) or discord.PermissionOverwrite()
overwrite.send_messages = True
await self.bot.edit_channel_permissions(ctx.message.channel, user, overwrite)
tmp = await self.bot.send_message(ctx.message.channel, "{} is no longer muted here! He/she can speak now!".format(user.mention))
await asyncio.sleep(5)
await self.bot.delete_message(tmp)
else:
tmp = await self.bot.say("```\nVous n'avez pas la permission d'utiliser cette commande\n```")
await asyncio.sleep(5)
await self.bot.delete_message(tmp)
def report(self, ctx, user: discord.Member, *, reason: str):
"""Reporte un utilisateur au staff"""
await self.bot.delete_message(ctx.message)
server = ctx.message.server
Channels = server.channels
End = []
Return = False
for chan in list(Channels):
Name = str(chan.name)
Type = str(chan.type)
if "moderation" in str(chan.name):
if Type is "text":
ModChan = chan
Return = True
if Return is not True:
ModChan = await self.bot.create_channel(server, 'moderation', type=discord.ChannelType.text)
await self.bot.send_message(ModChan, "{0} a été report par {1}, raison : {2}, @here".format(user.mention, ctx.message.author.mention, reason))
def money(self, ctx, *, user:discord.Member=None):
"""Affiche votre cagnotte"""
data = casino.start()
server = ctx.message.server
if not user:
user = ctx.message.author
chan = ctx.message.channel
await self.bot.delete_message(ctx.message)
money = casino.get(server, user, data)
mon_embed = discord.Embed()
mon_embed.colour = 0x3498db
mon_embed.title = "Cagnotte : {}$".format(str(money))
mon_embed.set_footer(text = "{0}#{1}".format(user.name, user.discriminator), icon_url = user.avatar_url)
await self.bot.say(embed = mon_embed)
def add_money(self, ctx, *, user:discord.Member=None):
"""Ajoute de l'argent à la cagnotte d'un utilisateur
Bot Master uniquement"""
data = casino.start()
server = ctx.message.server
if not user:
user = ctx.message.author
chan = ctx.message.channel
if ctx.message.author.id == "187565415512276993":
await self.bot.delete_message(ctx.message)
tmp = await self.bot.say("Combien voulez-vous ajouter à la cagnotte de {} ?".format(user.name))
ans = await self.bot.wait_for_message(author = ctx.message.author, channel = chan)
money = int(ans.content)
await self.bot.delete_message(ans)
casino.post(server, user, data, money)
await self.bot.delete_message(tmp)
tmp = await self.bot.say("Done")
await asyncio.sleep(3)
await self.bot.delete_message(tmp)
else:
return
def format_new_score(mode: api.GameMode, score: dict, beatmap: dict, rank: int, member: discord.Member):
""" Format any score. There should be a member name/mention in front of this string. """
acc = calculate_acc(mode, score)
return (
"[{i}{artist} - {title} [{version}]{i}]({host}b/{beatmap_id})\n"
"**{pp}pp {stars:.2f}\u2605, {rank} {scoreboard_rank}+{mods}**"
"```diff\n"
" acc 300s 100s 50s miss combo\n"
"{sign} {acc:<8.2%}{count300:<7}{count100:<7}{count50:<7}{countmiss:<7}{maxcombo}{max_combo}```"
"{live}"
).format(
host=host,
sign="!" if acc == 1 else ("+" if score["perfect"] == "1" else "-"),
mods=Mods.format_mods(int(score["enabled_mods"])),
acc=acc,
artist=beatmap["artist"].replace("_", "\_"),
title=beatmap["title"].replace("_", "\_"),
i="*" if "*" not in beatmap["artist"] + beatmap["title"] else "", # Escaping asterisk doesn't work in italics
version=beatmap["version"],
stars=float(beatmap["difficultyrating"]),
max_combo="/{}".format(beatmap["max_combo"]) if mode in (api.GameMode.Standard, api.GameMode.Catch) else "",
scoreboard_rank="#{} ".format(rank) if rank else "",
live=await format_stream(member, score, beatmap),
**score
)
def info(message: discord.Message, member: discord.Member=Annotate.Self):
""" Display configuration info. """
# Make sure the member is assigned
assert member.id in osu_config.data["profiles"], "No osu! profile assigned to **{}**!".format(member.name)
user_id = osu_config.data["profiles"][member.id]
mode = get_mode(member.id)
update_mode = get_update_mode(member.id)
e = discord.Embed(color=member.color)
e.set_author(name=member.display_name, icon_url=member.avatar_url, url=host + "u/" + user_id)
e.add_field(name="Game Mode", value=mode.name)
e.add_field(name="Notification Mode", value=update_mode.name)
e.add_field(name="Playing osu!", value="YES" if member.id in osu_tracking.keys() else "NO")
await client.send_message(message.channel, embed=e)
def can_use_command(cmd: Command, author, channel: discord.Channel=None):
""" Return True if the member who sent the message can use this command. """
if cmd.owner and not is_owner(author):
return False
if channel is not None and not has_permissions(cmd, author, channel):
return False
if not has_roles(cmd, author):
return False
# Handle server specific commands for both server and PM commands
if type(author) is discord.User and cmd.servers:
return False
if type(author) is discord.Member and not is_valid_server(cmd, author.server):
return False
return True
def addrole(self, ctx, rolename, user: discord.Member=None):
"""Adds a role to a user, defaults to author
Role name must be in quotes if there are spaces."""
author = ctx.message.author
channel = ctx.message.channel
server = ctx.message.server
if user is None:
user = author
role = self._role_from_string(server, rolename)
if role is None:
await self.bot.say('That role cannot be found.')
return
if not channel.permissions_for(server.me).manage_roles:
await self.bot.say('I don\'t have manage_roles.')
return
await self.bot.add_roles(user, role)
await self.bot.say('Added role {} to {}'.format(role.name, user.name))
def removerole(self, ctx, rolename, user: discord.Member=None):
"""Removes a role from user, defaults to author
Role name must be in quotes if there are spaces."""
server = ctx.message.server
author = ctx.message.author
role = self._role_from_string(server, rolename)
if role is None:
await self.bot.say("Role not found.")
return
if user is None:
user = author
if role in user.roles:
try:
await self.bot.remove_roles(user, role)
await self.bot.say("Role successfully removed.")
except discord.Forbidden:
await self.bot.say("I don't have permissions to manage roles!")
else:
await self.bot.say("User does not have that role.")
def check_roles(allowed_roles, all_users, user):
members = []
for member in all_users:
if isinstance(member, discord.Member):
if member.id == user.id:
members.append(member)
authorized = False
for member_item in members:
for allowed_role in allowed_roles:
role = discord.utils.find(lambda x: x.id == allowed_role, member_item.roles)
if role:
authorized = True
break
if authorized:
break
return authorized
def pat(self, context, member: discord.Member):
"""Pat your senpai/waifu!"""
author = context.message.author.mention
mention = member.mention
pat = "**{0} got patted by {1}!**"
choices = ['http://i.imgur.com/10VrpFZ.gif', 'http://i.imgur.com/x0u35IU.gif', 'http://i.imgur.com/0gTbTNR.gif', 'http://i.imgur.com/hlLCiAt.gif', 'http://i.imgur.com/sAANBDj.gif']
image = random.choice(choices)
embed = discord.Embed(description=pat.format(mention, author), colour=discord.Colour.blue())
embed.set_image(url=image)
await self.bot.say(embed=embed)
def kiss(self, context, member: discord.Member):
"""Kiss your senpai/waifu!"""
author = context.message.author.mention
mention = member.mention
kiss = "**{0} gave {1} a kiss!**"
choices = ['http://i.imgur.com/0D0Mijk.gif', 'http://i.imgur.com/TNhivqs.gif', 'http://i.imgur.com/3wv088f.gif', 'http://i.imgur.com/7mkRzr1.gif', 'http://i.imgur.com/8fEyFHe.gif']
image = random.choice(choices)
embed = discord.Embed(description=kiss.format(author, mention), colour=discord.Colour.blue())
embed.set_image(url=image)
await self.bot.say(embed=embed)
def hug(self, context, member: discord.Member):
"""Hug your senpai/waifu!"""
author = context.message.author.mention
mention = member.mention
hug = "**{0} gave {1} a hug!**"
choices = ['http://i.imgur.com/sW3RvRN.gif', 'http://i.imgur.com/gdE2w1x.gif', 'http://i.imgur.com/zpbtWVE.gif', 'http://i.imgur.com/ZQivdm1.gif', 'http://i.imgur.com/MWZUMNX.gif']
image = random.choice(choices)
embed = discord.Embed(description=hug.format(author, mention), colour=discord.Colour.blue())
embed.set_image(url=image)
await self.bot.say(embed=embed)
def _give_shop(self, ctx, user: discord.Member, *, itemname):
"""Adds an item to a users inventory. Item must be in the shop."""
author = ctx.message.author
settings = self.check_server_settings(author.server)
itemname = itemname.title()
self.user_check(settings, user)
if itemname in settings["Shop List"]:
quantity = 1
self.user_give_item(settings, user, quantity, itemname)
msg = "{} was given {} by {}".format(user.mention, itemname, author.mention)
else:
msg = "No such item in the shop."
await self.bot.say(msg)
def _gift_shop(self, ctx, user: discord.Member, quantity: int, *, itemname):
"""Send a number of items from your inventory to another user"""
if quantity < 1:
return await self.bot.say("Quantity must be higher than 0.")
author = ctx.message.author
itemname = itemname.title()
settings = self.check_server_settings(author.server)
self.user_check(settings, author)
self.user_check(settings, user)
if author == user:
await self.bot.say("This is awkward. You can't do this action with yourself.")
else:
await self.user_gifting(settings, user, author, itemname, quantity)
def _trade_shop(self, ctx, user: discord.Member, quantity: int, *, tradeoffer: str):
"""Request a trade with another user"""
author = ctx.message.author
tradeoffer = tradeoffer.title()
settings = self.check_server_settings(author.server)
self.user_check(settings, author)
self.user_check(settings, user)
result = self.trade_checks(settings, author, user, tradeoffer, quantity)
if result != "OK":
return await self.bot.say(result)
await self.trade_handler(settings, user, author, tradeoffer, quantity)
def _anime_mal(self, ctx, user: discord.Member=None):
"""Lookup another user's MAL for anime"""
author = ctx.message.author
cmd = "anime"
if not user:
user = author
await self.fetch_profile(user, author, cmd)