This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
68 lines (59 loc) · 2.39 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
# -*- coding: utf-8 -*-
import asyncio
import discord
import subprocess
import os
import requests
from urllib.parse import urljoin
import sqlite3
client = discord.Client()
connection = sqlite3.connect('grass.db')
cursor = connection.cursor()
BASEURL = "https://github.com"
COMMAND_BASE = "/usr/bin/curl '{url}' | awk '/<svg.+class=\"js-calendar-graph-svg\"/,/svg>/' | sed -e 's/<svg/<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\"/'>./images/"
@client.event
async def on_message(message):
if message.author.bot:
return
if message.content == '!leaf set':
await message.channel.send("設定します ユーザー名を続けて入力して下さい")
def check(command):
return command.author == message.author
reply = await client.wait_for("message", check=check)
grass = reply.content.lower()
url = urljoin(BASEURL, grass)
req = requests.get(url)
print(url)
print(req)
if req.status_code == requests.codes.ok:
image_name = grass + ".svg"
command = COMMAND_BASE.format(url=url) + image_name
print(command)
os.system(command)
file_name = "./images/" + image_name
converted_file_output = "--output=" + "./images/" + grass + ".png"
user_id = message.author.id
subprocess.run(["rsvg-convert", "--format=png", file_name, converted_file_output])
converted_file_name = grass + ".png"
sql = 'insert into grass (username, filename) values (?,?)'
namelist = (user_id, converted_file_name)
cursor.execute(sql, namelist)
connection.commit()
else:
await message.channel.send("存在していないuserです\n最初からやり直してください")
return
if message.content == '!leaf remove':
username = str(message.author.id)
select_sql = 'select * from grass where username=' + username
print(select_sql)
cursor.execute(select_sql)
result = cursor.fetchone()
img_name = "./images/" + img_name[1]
rm = "rm " + img_name
os.system(rm)
delete_sql = 'delete from grass where username=' + username
cursor.execute(delete_sql)
connection.commit()
await message.channel.send("削除が完了しました")
if __name__ == "__main__":
client.run(os.environ['LEAF_TOKEN'])