Skip to content

Commit

Permalink
Crayonbot upload
Browse files Browse the repository at this point in the history
  • Loading branch information
coma3009 authored Dec 1, 2021
0 parents commit cd3ca67
Show file tree
Hide file tree
Showing 66 changed files with 332,646 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# 📜 봇이름

## 짱구봇

## ✏️ 소개

이봇은 2021-12-01에 개발된 편한 시스템을 가지고 있는 봇입니다.

## 🛠️ 기능

- 🔰 관리
- 🧬 코로나현황
- 🧰 유틸리티
- 🕹️ 게임(미니게임)
- 🎵 음악
- 💴 도박
## 📌상세

<img src="https://cdn.discordapp.com/attachments/915556934977998879/915598995383017553/8585daca5a66c84e.png">
43 changes: 43 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import asyncio
from itertools import cycle
import os

import aiosqlite
import discord
import discordSuperUtils
from discord.ext import commands, tasks
from tools.autocogs import AutoCogs
from dotenv import load_dotenv
import threading
from pycord_components import PycordComponents
import config
load_dotenv(verbose=True)
class MyBot(commands.Bot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
AutoCogs(self)
self.remove_command("help")
async def on_ready(self):
"""Called upon the READY event"""
await self.change_presence(status=discord.Status.online, activity=discord.Activity(name="짱구야 도움",
type=discord.ActivityType.playing))
print("Bot is ready.")
async def is_owner(self, user):
if user.id in config.OWNER:
return True
@staticmethod
async def create_db_con():
db = await aiosqlite.connect("db/db.sqlite")
MyBot.db = discordSuperUtils.DatabaseManager.connect(database=db)




INTENTS = discord.Intents.all()
my_bot = MyBot(command_prefix=["짱구야 ","짱구야","ㄱ","ㄱ "], intents=INTENTS)


PycordComponents(my_bot)
if __name__ == "__main__":
my_bot.loop.run_until_complete(MyBot.create_db_con())
my_bot.run(os.getenv('TOKEN'))
192 changes: 192 additions & 0 deletions cogs/birthday.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
from datetime import datetime, timezone

import aiosqlite
import discord
import discordSuperUtils
import pytz
from discord.ext import commands


def ordinal(num: int) -> str:
"""
Returns the ordinal representation of a number
Examples:
11: 11th
13: 13th
14: 14th
3: 3rd
5: 5th
:param num:
:return:
"""

return (
f"{num}th"
if 11 <= (num % 100) <= 13
else f"{num}{['th', 'st', 'nd', 'rd', 'th'][min(num % 10, 4)]}"
)


class birthday(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.ImageManager = discordSuperUtils.ImageManager()
self.BirthdayManager = discordSuperUtils.BirthdayManager(self.bot)


@discordSuperUtils.CogManager.event(discordSuperUtils.BirthdayManager)
async def on_member_birthday(self, birthday_member):
# Incase you want to support multiple guilds, you must create a channel system.
# For example, to create a channel system you can make a "set_birthday_channel" command, and in on_member_birthday,
# you can fetch the same channel and send birthday updates there.
# Hard coding the channel ID into your code will work, but only on ONE guild (specifically, where the same channel
# is located) other guilds wont have the same channel, meaning it wont send them birthday updates.
# I advise of making a channel system, I do not recommend hard coding channel IDs at all unless you are SURE
# the channel IDs wont be changed and the bot is not supposed to work on other guilds.
channels = birthday_member.member.guild.text_channels
for channel in channels:
if (
channel.topic is not None
and str(channel.topic).find("-HOnBtd") != -1
):
channel = birthday_member.member.guild.get_channel(channel.id)
if channel:
embed = discord.Embed(
title="생일 축하합니다!! 🥳",
description=f"{ordinal(await birthday_member.age())}번째 생일을 축하드립니다!🎉, {birthday_member.member.mention}!",
color=0x00FF00,
)

embed.set_thumbnail(url=birthday_member.member.avatar_url)

await channel.send(content=birthday_member.member.mention, embed=embed)

@commands.command(name="생일목록")
async def upcoming(self, ctx):
await self.BirthdayManager.connect_to_database(self.bot.db, ["birthdays"])
guild_upcoming = await self.BirthdayManager.get_upcoming(ctx.guild)
formatted_upcoming = [
f"멤버: {x.member}, 나이: {await x.age()}, 생일: {(await x.birthday_date()):'%Y %b %d'}"
for x in guild_upcoming
]

await discordSuperUtils.PageManager(
ctx,
discordSuperUtils.generate_embeds(
formatted_upcoming,
title="다가오는 생일들",
fields=25,
description=f"{ctx.guild}에서 다가오는 생일 목록!",
),
).run()

@commands.command(name="생일")
async def birthday(self, ctx, member: discord.Member = None):
database = self.bot.db
await self.BirthdayManager.connect_to_database(database, ["birthdays"])
member = ctx.author if member is None else member
member_birthday = await self.BirthdayManager.get_birthday(member)

if not member_birthday:
await ctx.send("지정한 유저 혹은 명령자님은 생일 등록이 되어있지 않아요!")
return

embed = discord.Embed(title=f"{member}님의 생일", color=0x00FF00)

embed.add_field(
name="생일",
value=(await member_birthday.birthday_date()).strftime("%Y %b %d"),
inline=False,
)

embed.add_field(
name="시간대", value=await member_birthday.timezone(), inline=False
)

embed.add_field(name="나이", value=str(await member_birthday.age()), inline=False)

await ctx.send(embed=embed)

@commands.command(name="생일삭제")
async def delete_birthday(self, ctx):
# You can make the command admin-only, take the member as a parameter etc.
database = self.bot.db
await self.BirthdayManager.connect_to_database(database, ["birthdays"])
birthday_member = await self.BirthdayManager.get_birthday(ctx.author)
if not birthday_member:
await ctx.send("생일을 등록하지 않으셨어요!")
return

birthday_partial = await birthday_member.delete()

embed = discord.Embed(title=f"{ctx.author}님의 생일을 삭제했어요.", color=0x00FF00)

embed.add_field(
name="출생일", value=str(birthday_partial.birthday_date), inline=False
)
embed.add_field(name="시간대", value=birthday_partial.timezone, inline=False)

await ctx.send(embed=embed)

@commands.command(name="생일등록")
async def setup_birthday(self, ctx):
await self.BirthdayManager.connect_to_database(self.bot.db, ["birthdays"])
questions = [
f"{ctx.author.mention}, 태어난 연도는 언제인가요? 예시) 2000",
f"{ctx.author.mention}, 태어난 달은 언제인가요? 예시) 10",
f"{ctx.author.mention}, 태어난 일은 언제인가요? 예시) 2",
f"{ctx.author.mention}, 시간대는 뭔가요? 목록: https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568"
"\n또는 다음 링크에 접속해서 알아볼 수 있어요.: "
"http://scratch.andrewl.in/timezone-picker/example_site/openlayers_example.html"
"\n한국이면 `Asia/Seoul` 입력해주세요!",
]
# BirthdayManager uses pytz to save timezones and not raw UTC offsets, why?
# well, simply, using UTC offsets will result in a lot of confusion. The user might pass an incorrect UTC offset
# and he cloud be wished a happy birthday before his birthday. (The UTC offsets might have issues with DST, too!)
# that's why we chose pytz, to make custom timezones user-friendly and easy to setup.

answers, timed_out = await discordSuperUtils.questionnaire(
ctx, questions, member=ctx.author
)
# The questionnaire supports embeds.

if timed_out:
await ctx.send("시간이 지났어요.")
return

for answer in answers[:-1]:
if not answer.isnumeric():
await ctx.send("설정이 실패했어요.")
return

i = answers.index(answer)
answers[i] = int(answer)

if answers[3] not in pytz.all_timezones:
await ctx.send("설정을 실패했어요, 입력한 시간대를 찾지못했어요.")
return

try:
now = datetime.now(tz=timezone.utc)
date_of_birth = datetime(*answers[:-1], tzinfo=timezone.utc)
if date_of_birth > now:
await ctx.send("설정을 실패했어요. 입력한 달이나 일이 미래에요")
return
except ValueError:
await ctx.send("설정을 실패했어요.")
return

member_birthday = await self.BirthdayManager.get_birthday(ctx.author)
if member_birthday:
await member_birthday.set_birthday_date(date_of_birth.timestamp())
await member_birthday.set_timezone(answers[3])
else:
await self.BirthdayManager.create_birthday(
ctx.author, date_of_birth.timestamp(), answers[3]
)

await ctx.send(f"성공적으로 생일을 다음과 같이 등록했어요! {date_of_birth:%Y %b %d }.")


def setup(bot):
bot.add_cog(birthday(bot))
Loading

0 comments on commit cd3ca67

Please sign in to comment.