-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
102 lines (75 loc) · 2.84 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import discord
import re
import random
import os
import urllib.request
import json
import time,asyncio
import threading
import diceroll
import diceparse
client = discord.Client()
pattern = re.compile(r'((\d)[dD](\d+))(.*)')
parser_pattern = re.compile(r'^\(?\d+[dD][\ddD\(\)\+\-\*]*\d+\)?(.*)')
reaction_pattern = ['それな', 'わかる', '本当か?', 'おちつけよ', 'キウイ食うか?', '確かに', '爆弾発言だな(笑)']
def getLiveDataList():
url = 'http://holodule-now-server.herokuapp.com/api/schedule/now'
res = urllib.request.urlopen(url=url).read()
live_datas = json.loads(res.decode('utf-8'))
return live_datas
@client.event
async def on_ready():
print('Logged in.')
@client.event
async def on_message(message):
if message.content == '!bye':
await client.close()
if message.author.bot:
return
if random.randrange(0,100)<1:
await message.channel.send( message.author.mention + " " + random.choice(reaction_pattern))
if message.content == 'ホロライブの配信見たいな':
await message.channel.send( (message.author.mention)+'\nなんだと?')
datas = getLiveDataList()
if len(datas)==0:
await message.channel.send( 'しかし残念だが、今は誰も配信していないようだ...')
return
await message.channel.send( 'ならばこちらの配信はいかがだろうか')
for d in datas:
await message.channel.send( d['streaming']['url'])
await message.channel.send( 'スパチャの準備はできたか?')
return
dice_parser_reg = parser_pattern.search(message.content)
if dice_parser_reg:
msg = message.author.mention + "\n"
msg += str(diceparse.DiceParser(dice_parser_reg.group(0)).evaluate())
if dice_parser_reg.group(1).find("シークレット")!=-1:
await message.author.send(msg)
return
await message.channel.send( msg)
return
message_reg = pattern.search(message.content)
if(message_reg):
res = diceroll.Dice.roll_with_pattern(message_reg.group(1))
send_msg = message.author.mention + "\n"
if(message_reg.group(4)!=""):
send_msg += "Dice rolled for \"*" + message_reg.group(4).strip() + "*\"\n"
send_msg += "res: " + str(res) + "-> __**" + str(sum(res)) + "**__\n"
print(send_msg)
send_for = message.channel
if(message_reg.group(4).find("シークレット") != -1):
send_msg.replace("シークレット", "")
await message.author.send(send_msg)
else:
await message.channel.send(send_msg)
print(send_msg)
return
if random.randrange(0,100)<1:
await message.channel.send(message.author.mention + " " + random.choice(reaction_pattern))
def holodule_job():
print(getLiveDataList())
t=threading.Timer(300,holodule_job)
t.start()
t=threading.Thread(target=holodule_job)
t.start()
client.run(os.environ['DISCRD_TOKEN'])