-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscordBot.py
71 lines (58 loc) · 1.95 KB
/
discordBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import discord
from twitterApp import TwitterApp
from repositories.user import UserRepository
user = UserRepository()
twitterApp = TwitterApp()
class DiscordBot(discord.Client):
"""
Discord関連の処理を行う
Attributes
----------
usernames : set
監視対象のユーザー名の集合
activity_name : dict
ユーザーごとのアクティビティ名
"""
def __init__(self):
intents = discord.Intents.all()
intents.members = True
super().__init__(presences=True, guild_subscriptions=True, intents=intents)
async def on_ready(self):
"""
起動時に実行される関数
"""
print("-- LOGINED --")
async def on_message(self, message: discord.Message):
"""
メンションされた時に実行される関数
DMにidを送信する
Parameters
----------
message : discord.Message
メッセージに関する情報
"""
if message.author.bot:
return
dm = await message.author.create_dm()
await dm.send(f"あなたのidは\n`{message.author.id}`")
async def on_member_update(self, before: discord.Member, after: discord.Member):
"""
メンバーに変化があったときに実行される関数
activity_nameを更新する
Parameters
----------
before : discord.Member
変更前のメンバー情報
after : discord.Member
変更後のメンバー情報
"""
uid: int = after.id
if not user.exists(uid):
return
if after.activity is None:
activity = "None"
print(f"{uid}がアクティビティを終了")
else:
activity: str = after.activity.to_dict()['name']
print(f"{uid}がアクティビティ{activity}を開始")
print(twitterApp.update_profile(uid, activity))