-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from paiza-learning/feat/update-discordjs
discordjs v13 への移行
- Loading branch information
Showing
26 changed files
with
812 additions
and
1,566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM node:14 as production | ||
FROM node:17 as production | ||
|
||
ENV NODE_ENV=production | ||
WORKDIR /usr/src/app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,22 @@ | ||
import { | ||
Command, | ||
CommandInfo, | ||
CommandoClient, | ||
CommandoMessage, | ||
} from 'discord.js-commando'; | ||
import { Command } from '../../models/command'; | ||
|
||
import fetch from 'node-fetch'; | ||
import yaml from 'js-yaml'; | ||
import debug from 'debug'; | ||
|
||
const mojamojaURL = 'https://www.mojamoja.cloud/api/v1/environment/latest'; | ||
|
||
export default class MojaCommand extends Command { | ||
constructor(client: CommandoClient) { | ||
super(client, { | ||
name: 'moja', | ||
group: 'fun', | ||
memberName: 'moja', | ||
description: 's10akir の自室の環境情報を得ることができます.', | ||
} as CommandInfo); | ||
} | ||
|
||
async run(msg: CommandoMessage): Promise<CommandoMessage> { | ||
const result = await fetch(mojamojaURL, { method: 'GET' }) | ||
.then((resp) => resp.json()) | ||
.then((data) => { | ||
debug(data); | ||
return '```yaml\n' + yaml.dump(data) + '```'; | ||
}); | ||
|
||
return msg.say(result); | ||
} | ||
async function main() { | ||
return await fetch(mojamojaURL, { method: 'GET' }) | ||
.then((resp) => resp.json()) | ||
.then((data) => { | ||
debug(data); | ||
return '```yaml\n' + yaml.dump(data) + '```'; | ||
}); | ||
} | ||
|
||
Command.register('moja', { | ||
desc: '@s10akir の自室の環境情報を取得します。', | ||
exec: main, | ||
help: '@s10akir の自室の環境情報を取得します。', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,24 @@ | ||
import { | ||
Command, | ||
CommandInfo, | ||
CommandoClient, | ||
CommandoMessage, | ||
} from 'discord.js-commando'; | ||
|
||
import { Command } from '../../models/command'; | ||
import { Message, MessageAttachment } from 'discord.js'; | ||
|
||
import fetch from 'node-fetch'; | ||
import debug from 'debug'; | ||
|
||
const shibeURL = 'http://shibe.online/api/shibes?count=1]&urls=true'; | ||
|
||
export default class ShibeCommand extends Command { | ||
constructor(client: CommandoClient) { | ||
super(client, { | ||
name: 'shibe', | ||
group: 'fun', | ||
memberName: 'shibe', | ||
description: 'わんこの画像が見れるわん', | ||
} as CommandInfo); | ||
} | ||
|
||
async run(msg: CommandoMessage): Promise<Message> { | ||
const result = await fetch(shibeURL, { method: 'GET' }) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
debug(data[0]); | ||
return data[0]; | ||
}); | ||
const attachment = new MessageAttachment(result); | ||
|
||
return msg.channel.send(attachment); | ||
} | ||
async function main(_1: string[], _2: string, msg: Message) { | ||
const result = await fetch(shibeURL, { method: 'GET' }) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
debug(data[0]); | ||
return data[0]; | ||
}); | ||
const attachment = new MessageAttachment(result); | ||
msg.channel.send({ files: [attachment] }); | ||
} | ||
|
||
Command.register('shibe', { | ||
desc: 'わんこの画像が見れるわん', | ||
exec: main, | ||
help: 'わんこの画像が見れるわん', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import './fun/moja'; | ||
import './fun/shibe'; | ||
|
||
import './paiza/hello'; | ||
import './paiza/paizaIO'; | ||
import './paiza/reactme'; | ||
|
||
import './utility/help'; | ||
// import './utility/query'; | ||
|
||
// import './todo'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
import { | ||
Command, | ||
CommandInfo, | ||
CommandoClient, | ||
CommandoMessage, | ||
} from 'discord.js-commando'; | ||
import { Command } from '../../models/command'; | ||
|
||
export default class HelloCommand extends Command { | ||
constructor(client: CommandoClient) { | ||
super(client, { | ||
name: 'hello', | ||
group: 'paiza', | ||
memberName: 'hello', | ||
description: 'hello', | ||
} as CommandInfo); | ||
} | ||
|
||
run(msg: CommandoMessage): Promise<CommandoMessage> { | ||
return msg.say('hello'); | ||
} | ||
} | ||
Command.register('hello', { | ||
desc: 'hello', | ||
exec: async () => 'hello', | ||
help: 'hello', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,9 @@ | ||
import { | ||
Command, | ||
CommandInfo, | ||
CommandoClient, | ||
CommandoMessage, | ||
} from 'discord.js-commando'; | ||
import { Command } from '../../models/command'; | ||
|
||
interface ReactMeArgument { | ||
emoji: string; | ||
} | ||
|
||
export default class ReactMeCommand extends Command { | ||
constructor(client: CommandoClient) { | ||
super(client, { | ||
name: 'reactme', | ||
group: 'paiza', | ||
memberName: 'reactme', | ||
description: '投稿に指定したリアクションをしてくれます.', | ||
args: [ | ||
{ | ||
key: 'emoji', | ||
prompt: 'What would you like me to react with?', | ||
type: 'string', | ||
}, | ||
], | ||
} as CommandInfo); | ||
} | ||
|
||
async run(msg: CommandoMessage, args: ReactMeArgument): Promise<null> { | ||
msg.react(args.emoji); | ||
return null; | ||
} | ||
} | ||
Command.register('reactme', { | ||
desc: '投稿に指定したリアクションをしてくれます', | ||
exec: async (args, _, msg) => { | ||
msg.react(args[0]); | ||
}, | ||
help: '投稿に指定したリアクションをしてくれます', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Command } from '../models/command'; | ||
import { Todo } from '../entities/todo'; | ||
import { Message } from 'discord.js'; | ||
|
||
async function main(args: string[], _: string, msg: Message) { | ||
switch (args[0]) { | ||
case 'add': | ||
addTodo(args, msg); | ||
break; | ||
case 'del': | ||
delTodo(args, msg); | ||
break; | ||
case 'list': | ||
listTodo(msg); | ||
break; | ||
} | ||
} | ||
|
||
async function addTodo(args: string[], msg: Message) { | ||
const userId = msg.author.id; | ||
|
||
const todo = new Todo(); | ||
todo.userId = userId; | ||
todo.title = args[0]; | ||
|
||
await todo.save(); | ||
|
||
return msg.reply(`success. [${todo.title}]`); | ||
} | ||
|
||
async function delTodo(args: string[], msg: Message) { | ||
const todo = await Todo.findOne(args[0]); | ||
const userId = msg.author.id; | ||
|
||
if (!todo) { | ||
return msg.reply('[!] todo does not exists.'); | ||
} | ||
|
||
if (todo.userId !== userId) { | ||
return msg.reply('[!] you are not owner of this todo.'); | ||
} | ||
|
||
const todo_title = todo.title; | ||
await todo.remove(); // DBの容量節約にレコードを物理削除 | ||
|
||
return msg.reply(`success! remove [${todo_title}]`); | ||
} | ||
|
||
async function listTodo(msg: Message) { | ||
const user = msg.author; | ||
|
||
const todos = await Todo.find({ userId: user.id }); | ||
let text: string; | ||
|
||
if (todos.length !== 0) { | ||
const todoList = [`${user.username}'s TODO LIST:`]; | ||
todos.forEach((todo) => { | ||
todoList.push(`- ${todo.id}: ${todo.title}`); | ||
}); | ||
text = todoList.join('\n'); | ||
} else { | ||
text = ':tada: LGTM! :tada: WE ARE FREE!'; | ||
} | ||
|
||
return msg.reply(text); | ||
} | ||
|
||
Command.register('todo', { | ||
desc: 'manage your todo', | ||
exec: main, | ||
help: `usage todo [add|del|list] | ||
add: add todo | ||
todo add [title] | ||
del: delete todo | ||
todo del [id] | ||
list: list todo`, | ||
}); |
Oops, something went wrong.