Skip to content

Commit

Permalink
Merge pull request #4 from sw08/main
Browse files Browse the repository at this point in the history
서버와 깃허브 간 코드 동기화
  • Loading branch information
happy-jin1234 authored Dec 18, 2021
2 parents 84f8972 + 0b795ce commit 64707c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Cogs/_01_usermeme.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def _upload(self, ctx):
(img_msg.id, ctx.author.id, title, img_msg.attachments[0].url, str(img_msg.created_at)),
)
await msg.edit(
content=f"짤 업로드 완료\n짤 ID: {img_msg.id}", embed=None, components=[]
embed=discord.Embed(title=f"짤 업로드 완료\n짤 ID: {img_msg.id}", color=embedcolor), components=[]
)

@commands.command(
Expand Down
11 changes: 6 additions & 5 deletions Cogs/_02_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def _help(self, ctx, *, help_=None):
[공식 서버](http://support.memebot.kro.kr) \
\n\n> <>는 봇을 사용하는 데에 있어서 필수적인 값, []는 필수적이지 않은 값입니다. \
\n> `[]`와 `<>`는 빼고 입력해 주세요. \
\n\n> **Made by {await self.bot.fetch_user(745848200195473490)}**\n",
\n\n> **Made by {await self.bot.fetch_user(726350177601978438)} and {await self.bot.fetch_user(443691722543726592)}, Studio Orora**\n",
color=embedcolor,
)
embed.set_footer(text=f'{ctx.guild} 서버의 접두사는 "{prefix}"입니다')
Expand All @@ -65,13 +65,14 @@ async def _help(self, ctx, *, help_=None):
if ctx.author.id not in self.bot.owner_ids:
if i in ["오너", "Jishaku"]:
continue
cmds = [j for j in cogs[i].get_commands()]
for j in cmds:
cmds_all = [j for j in cogs[i].get_commands()]
cmds_available = [j for j in cmds_all]
for j in cmds_all:
if not j.enabled:
del cmds[cmds.index(j)]
cmds_available.remove(j)
embed.add_field(
name=f"**{i}**",
value="**" + " ".join([j.name for j in cmds]) + "**",
value="**" + " ".join([j.name for j in cmds_available]) + "**",
)
return await ctx.reply(embed=embed)
cmd = self.bot.get_command(help_)
Expand Down
71 changes: 13 additions & 58 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from os import listdir, remove
from pickle import load
from shutil import copy2

from koreanbots import Koreanbots
import aiofiles
import aiohttp
import aiosqlite as aiosql
Expand Down Expand Up @@ -32,46 +32,14 @@
)
presences = []
component = DiscordComponents(bot)
# discord.Message.reply = reply_component_msg_prop
if not test:
with open('koreanbots_token.bin', 'rb') as kbtoken:
kbtoken = load(kbtoken)
koreanbots = Koreanbots(bot, kbtoken, run_task=True)


@bot.event
async def on_ready():
global presences
presences = cycle(
[
discord.Activity(
name="짤",
type=discord.ActivityType.watching,
large_image_url=bot.user.avatar_url,
),
discord.Activity(
name="ㅉhelp",
type=discord.ActivityType.listening,
large_image_url=bot.user.avatar_url,
),
discord.Activity(
name=f"{len(bot.guilds)}서버",
type=discord.ActivityType.playing,
large_image_url=bot.user.avatar_url,
),
discord.Activity(
name="http://invite.memebot.kro.kr",
type=discord.ActivityType.watching,
large_image_url=bot.user.avatar_url,
),
discord.Activity(
name="http://support.memebot.kro.kr",
type=discord.ActivityType.watching,
large_image_url=bot.user.avatar_url,
),
discord.Activity(
name="http://koreanbots.memebot.kro.kr",
type=discord.ActivityType.watching,
large_image_url=bot.user.avatar_url,
),
]
)
async with aiosql.connect("memebot.db", isolation_level=None) as cur:
await cur.execute(
"CREATE TABLE IF NOT EXISTS usermeme (id INTEGER PRIMARY KEY, uploader_id INTEGER, title text, url text,\
Expand All @@ -97,7 +65,6 @@ async def on_ready():
print("ready")
if not test:
await backupdb()
update_koreanbots.start()
backupdb.start()
change_presence.start()
else:
Expand All @@ -106,9 +73,15 @@ async def on_ready():
await bot.get_channel(852767242704650290).send(("테봇 " if test else "") + "켜짐")


@tasks.loop(seconds=10)
@tasks.loop(minutes=30)
async def change_presence():
await bot.change_presence(activity=next(presences))
await bot.change_presence(
activity=discord.Activity(
name="{len(bot.guilds)}서버",
type=discord.ActivityType.playing,
large_image_url=bot.user.avatar_url,
)
)


@tasks.loop(hours=4)
Expand All @@ -120,23 +93,6 @@ async def backupdb():
)


@tasks.loop(minutes=30)
async def update_koreanbots():
with open("koreanbots_token.bin", "rb") as f:
koreanbots_token = load(f)
async with aiohttp.ClientSession() as session:
async with session.post(
"https://koreanbots.dev/api/v2/bots/875908453548326922/stats",
data={"servers": len(bot.guilds), "shards": 1},
headers={"Authorization": koreanbots_token},
) as res:
if res.status != 200:
print(res)
await (bot.get_channel(852767242704650290)).send(
f"Koreanbots API 요청에 실패함\n{await res.json()}"
)


@bot.event
async def on_guild_join(guild):
embed = discord.Embed(title="서버 참여", color=embedcolor)
Expand Down Expand Up @@ -261,7 +217,6 @@ async def on_button_click(interaction):
async with session.get(embed.image.url) as resp:
async with aiofiles.open(filename, "wb") as f:
await f.write(await resp.read())
print(interaction.values)
await bot.get_channel(869414081411567676).send(
f"{interaction.author.mention}: `{'`, `'.join([i for i in list(interaction.values)])}`",
file=discord.File(filename),
Expand Down

0 comments on commit 64707c2

Please sign in to comment.