Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:GoogleCalendarにイベントを追加するコマンド #6

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d3ea4ef
feat: GoogleCalenderにイベント追加コマンド
peijun Aug 8, 2020
730e4b3
test: GoogleCalenderのコマンドパースのテスト
peijun Aug 8, 2020
865304d
Update: .env-example
peijun Aug 9, 2020
d44414c
refactor: function name
peijun Aug 9, 2020
686c91c
refactor: command split in logic
peijun Aug 9, 2020
a8d2e89
fix: レビューni
peijun Aug 9, 2020
9874d79
fix: レビューによる変更に対する修正
peijun Aug 9, 2020
eafa8a0
Merge remote-tracking branch 'origin/feature-calender' into feature-c…
peijun Aug 9, 2020
047e83f
refactor: code formatting
peijun Aug 9, 2020
377ac3e
fix: 変更漏れ
peijun Aug 9, 2020
63f1f74
fix: 関数名の変更漏れ
peijun Aug 9, 2020
78148e0
bot.pyにプラグインを追加
peijun Aug 9, 2020
1a65312
fix カンマ忘れ
peijun Aug 9, 2020
240420e
refactor:返り値Noneの明示
peijun Aug 10, 2020
1fd908a
refactor: import文のsort
peijun Aug 10, 2020
02000b6
feat: WEBHOOKをIFTTTからazure functionsに変更
peijun Aug 11, 2020
5b62191
dataclassの導入
peijun Aug 12, 2020
5c91aa0
webhookを使わないで実装
peijun Aug 13, 2020
c6a7351
依存の更新
peijun Aug 13, 2020
2f0f2ab
webhookを使わない実装
peijun Aug 13, 2020
a6c4e2d
Merge remote-tracking branch 'origin/feature-calender' into feature-c…
peijun Aug 13, 2020
f02aa29
ミス
peijun Aug 13, 2020
e3b743c
Eventを扱いやすく
peijun Aug 13, 2020
4f703fa
scheduleからeventへ統一
peijun Aug 13, 2020
913e915
Eventの一部をproperty化
peijun Aug 13, 2020
78f0f6d
関数の返り値の間違いを修正
peijun Aug 13, 2020
5ee9186
突貫工事テスト
peijun Aug 13, 2020
f7a619d
使ってないモジュールの削除
peijun Aug 13, 2020
da6aa58
key.jsonをignore
peijun Aug 15, 2020
a4339c3
Merge branch 'master' into feature-calender
peijun Aug 15, 2020
a68c363
staticmethod化
peijun Aug 15, 2020
94a471d
dictの方ヒント
peijun Aug 15, 2020
e311c65
変数の重複を解消
peijun Aug 15, 2020
0050558
unusedな変数を削除
peijun Aug 15, 2020
d6e6954
add_eventにdictかNoneを返すように指定
peijun Aug 15, 2020
df42a5d
_create_event_objをstaticmethod化
peijun Aug 15, 2020
1f59b70
型ヒントを追加
peijun Aug 15, 2020
d603b91
テスト用classの作成
peijun Aug 15, 2020
5a3bce8
unusedなモジュールの削除
peijun Aug 15, 2020
181c9e8
余分な改行を削除
peijun Aug 15, 2020
e04e232
変数名を変更
peijun Aug 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DISCORD_BOT_TOKEN=xxxxxxxx
CALENDAR_WEBHOOK=xxxxxxxx
peijun marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 35 additions & 0 deletions logic/calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import urllib.request, json
from os import getenv

class CalendarImpl:
def command_parse(text: str):
command = text.split(" ")

title = command[0]
dateindex = int(command.index("-d") + 1)
date = command[dateindex]
locationindex = int(command.index("-l") + 1)
location = command[locationindex]
peijun marked this conversation as resolved.
Show resolved Hide resolved

obj = {"value1" : date, "value2" : title, "value3" : location}
json_data = json.dumps(obj).encode("utf-8")

return json_data

@classmethod
def add_event(cls, text: str):
message = "Success!"

# set up POST data
url = getenv("CALENDAR_WEBHOOK")
method = "POST"
headers = {"Content-Type": "application/json"}

json_data= command_parse(text)

peijun marked this conversation as resolved.
Show resolved Hide resolved
# http request
request = urllib.request.Request(url, data=json_data, method=method, headers=headers)
urllib.request.urlopen(request)

return message
peijun marked this conversation as resolved.
Show resolved Hide resolved

18 changes: 18 additions & 0 deletions plugin/calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from discord.ext.commands import Bot
from discord.ext.commands import Cog
from discord.ext.commands import Context
from discord.ext.commands import command
from logic.calendar import CalendarImpl

class Calendar(Cog):
def __init__(self, bot: Bot) -> None:
self.bot = bot


@command()
async def add_event(self, ctx: Context, arg: str) -> None:
result = CalendarImpl.add_event(arg)
await ctx.send(result)
peijun marked this conversation as resolved.
Show resolved Hide resolved

def setup(bot):
bot.add_cog(Calendar(bot))
10 changes: 10 additions & 0 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from logic.calendar import CalendarImpl
import json

sample_command = "testtitle -d 10/10 -l japan"

def test_command_parse():
result = CalendarImpl.command_parse(text=sample_command)
obj = {"value1" : "10/10", "value2" : "testtitle", "value3" : "japan"}
json_data = json.dumps(obj).encode("utf-8")
assert result == json_data