Skip to content

Commit

Permalink
Merge pull request #117 from mii-10/master
Browse files Browse the repository at this point in the history
  • Loading branch information
takumi0213 committed Jun 15, 2023
2 parents bdb7fb4 + b61ec52 commit f6bcd06
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ my_module/dpy_interaction.py
ment.py
.gitignore
trans_db.py
cogs/_m10s_api.py
cogs/m10s_api.py
cogs/slash/pjsekai_music_select.py
pjsekai_musics.json
api_cf_ssl/
35 changes: 25 additions & 10 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
intents=intents,
enable_debug_events=True
)
"""bot = commands.Bot(command_prefix="s-", status=discord.Status.invisible,
allowed_mentions=discord.AllowedMentions(everyone=False),
intents=intents,
enable_debug_events=True,
shard_id=0,
shard_count=2
)"""
bot.owner_id = None
bot.owner_ids = {404243934210949120, 525658651713601536}
bot.maintenance = False
Expand Down Expand Up @@ -158,13 +165,13 @@ async def get_context(msg, cls=LocalizedContext):
rpcs = [
"ヘルプ:s-help",
"アイコン:しおさばきゅーさん",
"サーバー数:{0}",
"ユーザー数:{1}",
"サーバー数:{0}/ユーザー数:{1}",
"シャード番号:{2}",
"作成:チーム☆思惟奈ちゃん",
"help:s-help",
"icon:しおさばきゅー",
"{0}guilds",
"{1}users",
"{0}guilds/{1}users",
"shard id:{2}",
"created by team-sina"
]
"""db = dropbox.Dropbox(DROP_TOKEN)
Expand Down Expand Up @@ -249,7 +256,7 @@ async def cRPC():
rpcct = 0
else:
rpcct = rpcct+1
await bot.change_presence(status=discord.Status.online, activity=discord.Game(name=rpcs[rpcct].format(len(bot.guilds), len(bot.users))))
await bot.change_presence(status=discord.Status.online, activity=discord.Game(name=rpcs[rpcct].format(len(bot.guilds), len(bot.users), bot.shard_id)))



Expand All @@ -274,7 +281,7 @@ async def on_ready():
"m10s_auth_wiz",
"m10s_role_panel", "m10s_partners", "m10s_remainder", "m10s_set_activity_roles",

"_m10s_api", "takumi_twinotif",
"m10s_api", "takumi_twinotif",
"m10s_app_metadata",

# "__part_pjsekai_music_select"
Expand All @@ -283,12 +290,13 @@ async def on_ready():
"slash.m10s_messageinfo", # -> メッセージコマンドでの実行

"hybrid.m10s_re_gchat",
"hybrid._m10s_quick_cmd",
"hybrid.m10s_quick_cmd",
"hybrid.m10s_levels",
"hybrid.m10s_music",
"hybrid.info_check",
"hybrid.m10s_help",
"m10s_guild_log"
"m10s_guild_log",
"m10s_direct_msg"
]

embed = discord.Embed(title="読み込みに失敗したCog", color=bot.ec)
Expand All @@ -314,9 +322,16 @@ async def on_ready():
# グローバルコマンド
await bot.tree.sync()

boot_info_channel_id = 595526013031546890

try:
ch = bot.get_channel(595526013031546890)
e=discord.Embed(title="起動時インフォメーション", description=f"認識ユーザー数:{len(bot.users)}\n認識サーバー数:{len(bot.guilds)}\n認識チャンネル数:{len([c for c in bot.get_all_channels()])}\ndiscord.py ver_{discord.__version__}", color=bot.ec)
ch = bot.get_channel(boot_info_channel_id)
if ch == None:
try:
await bot.fetch_channel(boot_info_channel_id)
except:
return
e=discord.Embed(title="起動時インフォメーション", description=f"シャードID:{bot.shard_id}\n認識ユーザー数:{len(bot.users)}\n認識サーバー数:{len(bot.guilds)}\n認識チャンネル数:{len([c for c in bot.get_all_channels()])}\ndiscord.py ver_{discord.__version__}", color=bot.ec)
await ch.send(f"{bot.get_emoji(653161518531215390)}on_ready!", embed=e)
if txt:
await ch.send(embed=embed)
Expand Down
8 changes: 4 additions & 4 deletions cogs/hybrid/m10s_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ async def level_add(self, ctx, target:Union[commands.MemberConverter,commands.Us
return await ctx.reply("> サーバーレベル編集-追加\n 引数が正しくありません。\n `[メンバーor役職を特定できるもの] [追加するレベル] [オプション:追加する経験値]`")
for m in targets:
lvl = await self.bot.cursor.fetchone("select * from levels where guild_id=%s and user_id=%s", (ctx.guild.id, m.id))
try:
if lvl:
await self.bot.cursor.execute("UPDATE levels SET level = %s, exp = %s WHERE guild_id = %s and user_id = %s", (lvl["level"] + lev, lvl["exp"] + exp, ctx.guild.id, m.id))
except:
else:
await self.bot.cursor.execute("INSERT INTO levels(user_id, guild_id, level, exp, last_level_count, is_level_count_enable) VALUE (%s, %s, %s, %s, %s, %s)", (m.id, ctx.guild.id, lev, exp, int(time.time()), 1))
await ctx.reply(f"> サーバーレベル編集\n {len(targets)}人のレベルを編集しました。(レベルがないメンバーには干渉していません。)")

Expand All @@ -403,9 +403,9 @@ async def level_set(self, ctx, target:Union[commands.MemberConverter,commands.Us
return await ctx.reply("> サーバーレベル編集-設定\n 引数が正しくありません。\n `[メンバーor役職を特定できるもの] [設定するレベル] [オプション:設定する経験値]`")
for m in targets:
lvl = await self.bot.cursor.fetchone("select * from levels where guild_id=%s and user_id=%s", (ctx.guild.id, m.id))
try:
if lvl:
await self.bot.cursor.execute("UPDATE levels SET level = %s, exp = %s WHERE guild_id = %s and user_id = %s", (lev, exp, ctx.guild.id, m.id))
except:
else:
await self.bot.cursor.execute("INSERT INTO levels(user_id, guild_id, level, exp, last_level_count, is_level_count_enable) VALUE (%s, %s, %s, %s, %s, %s)", (m.id, ctx.guild.id, lev, exp, int(time.time()), 1))

await ctx.reply(f"> サーバーレベル編集\n {len(targets)}人のレベルを設定しました。(レベルがないメンバーには干渉していません。)")
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions cogs/m10s_app_metadata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import discord
from discord.ext import commands
from discord.ext import commands, tasks
import asyncio
from dateutil.relativedelta import relativedelta as rdelta
import traceback
Expand Down Expand Up @@ -32,8 +32,8 @@ async def update_role_metadata(self, ctx):
{
"key":"isdonate",
"name":"思惟奈ちゃんプレミアム会員",
"description":"思惟奈ちゃんに寄付を行った、プレミアム会員である",
"type":7
"description":"思惟奈ちゃんプレミアム会員のランク",
"type":2
},
{
"key":"isverified",
Expand All @@ -58,6 +58,7 @@ async def update_role_metadata(self, ctx):

@commands.hybrid_command(description="あなたの接続されているアプリメタデータを更新します。")
async def sync_metadata(self, ctx:commands.Context):
await ctx.defer(ephemeral=True)
upf = await self.bot.cursor.fetchone("select oauth_ref_token from users where id=%s", (ctx.author.id,))
if upf["oauth_ref_token"]:
try:
Expand All @@ -67,7 +68,7 @@ async def sync_metadata(self, ctx:commands.Context):
else:
await ctx.send("完了しました。", ephemeral=True)
else:
await ctx.send("失敗しました。\nまだアプリ連携が行われていません。linked-rolesメニューから、思惟奈ちゃんの連携が有効なロールを探して連携してください。", ephemeral=True)
await ctx.send("失敗しました。\nまだアプリ連携が行われていません。Linked Rolesメニューから、思惟奈ちゃんの連携が有効なロールを探して連携してください。", ephemeral=True)


async def setup(bot):
Expand Down
47 changes: 47 additions & 0 deletions cogs/m10s_direct_msg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-

import discord
from discord.ext import commands, tasks
import asyncio
from dateutil.relativedelta import relativedelta as rdelta
import traceback
import m10s_util as ut
import textwrap

import config
import aiohttp

from discord import app_commands

class m10s_direct_msg(commands.Cog):

def __init__(self, bot):
self.bot: commands.Bot = bot

@commands.command()
@commands.is_owner()
@ut.runnable_check()
async def send_dm(self, ctx, target_id:int, *, content:str):
user = self.bot.get_user(target_id)
if user:
m = await ctx.author.send(f"`{str(user)}`に```\n{content}```と送信してもよろしいですか?")
await m.add_reaction("⭕")
await m.add_reaction("❌")
try:
r,u = await self.bot.wait_for("reaction_add", timeout=30, check=lambda r,u:u.id == ctx.author.id and str(r.emoji) in ["⭕","❌"])
except asyncio.TimeoutError:
await m.edit("タイムアウトしました。再度操作を行ってください。")
if str(r.emoji) == "⭕":
try:
await user.send(content)
except:
await ctx.author.send("送信に失敗しました。")
else:
await ctx.author.send("送信しました。")
else:
await ctx.author.send("キャンセルしました。")
else:
await ctx.author.send("該当ユーザーの取得に失敗しました。")

async def setup(bot):
await bot.add_cog(m10s_direct_msg(bot))
1 change: 1 addition & 0 deletions cogs/m10s_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ async def botinfo(self, ctx):
embed.add_field(name="全ユーザー数", value=len(self.bot.users))
embed.add_field(name="全チャンネル", value=len(
[i for i in self.bot.get_all_channels()]))
embed.add_field(name="シャードステータス", value=f"このサーバーのシャード番号:{self.bot.shard_id}(全{self.bot.shard_count}個)")
await ctx.send(embed=embed)

@commands.hybrid_command(name="return_text",aliases=["rt"], description="オウム返しします。")
Expand Down
3 changes: 2 additions & 1 deletion cogs/m10s_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async def getby(self, ctx, k: str):
async def search_commands(self,ctx):
pass

""" -> twitter APIの仕様変更によるもの
@search_commands.command(aliases=["twisearch", "twitterで検索して"], description="Twitter検索")
@app_commands.describe(word="検索文字列")
@commands.cooldown(1, 15, type=commands.BucketType.user)
Expand All @@ -57,7 +58,7 @@ async def twitter(self, ctx, *, word: str):
await ctx.send(embed=embed)
except:
await ctx.send(await ctx._("twi-error"))
# await ctx.send(embed=ut.getEmbed("traceback",traceback.format_exc(3)))
# await ctx.send(embed=ut.getEmbed("traceback",traceback.format_exc(3)))"""

@search_commands.command(aliases=["jwp", "次の言葉でwikipedia調べて"],description="wikipedia検索")
@app_commands.describe(word="検索文字列")
Expand Down
2 changes: 1 addition & 1 deletion m10s_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def predicate(ctx):
if ctx.client.comlocks.get(str(ctx.guild.id), []):
if ctx.command.name in ctx.bot.comlocks[str(ctx.guild.id)] and not ctx.author.guild_permissions.administrator and ctx.author.id != 404243934210949120: # comlockされているかどうか
return False
if ctx.command.name in ctx.bot.features[0] and (not ctx.guild.id in ctx.bot.team_sina): # グローバルfeatureでロックされているかどうか(メンテナンス)
if ctx.command.name in ctx.bot.features[0] and (not ctx.author.id in ctx.bot.team_sina): # グローバルfeatureでロックされているかどうか(メンテナンス)
return False
elif ctx.command.name in ctx.bot.features.get(ctx.author.id, []) or "cu:cmd" in ctx.bot.features.get(ctx.author.id, []): # featuresでのユーザーごとのコマンドロック
return False
Expand Down

0 comments on commit f6bcd06

Please sign in to comment.