Skip to content

Commit

Permalink
Merge pull request #14 from minarin0179/fix-remind
Browse files Browse the repository at this point in the history
remindのshardingに関するバグを修正
  • Loading branch information
minarin0179 authored Dec 8, 2023
2 parents 8db0594 + cd16fe6 commit e7ed8d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ services:
- TOKEN=***************
- DEV_SERVER_ID=***************
- mongodb=mongodb://mongodb:27017/agenda
- TZ=Asia/Tokyo
depends_on:
- mongo
33 changes: 19 additions & 14 deletions src/commands/slashcommands/remind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ export default new SlashCommand({
const day = args.getInteger("日", true);
const hour = args.getInteger("時", true);
const minute = args.getInteger("分", true);
// eslint-disable-next-line no-irregular-whitespace
const content = args.getString("本文", true).replace(/ {2}| {2}|\\n/g, "\n");
const destination = args.getChannel("送信先") ?? interaction.channel;

process.env.TZ = "Asia/Tokyo";

const date = new Date(year, month - 1, day, hour, minute);
const now = new Date();
const lim = new Date();
Expand Down Expand Up @@ -138,17 +137,23 @@ const buildEmbed = (content: string, date: Date, channelId: string) =>
);

agenda.define("send remind", async (job: any) => {
console.log("try to send remind");
const { channelId, authorId, content } = job.attrs.data;
const channel = await client.channels.fetch(channelId);
const author = await client.users.fetch(authorId);

console.log(channel)
if (!channel || !channel.isTextBased()) {
console.error("this channel is invalid");
return
}

await channel.send(content);
const { channelId, content } = job.attrs.data;
await job.remove();
await sendMessage(channelId, content);
});

const sendMessage = async (channelID: string, content: string) => {
// try to get guild from all the shards
const req = await client.shard?.broadcastEval(
(c, { channelID, content }) => {
const channel = c.channels.cache.get(channelID);
if (channel?.isTextBased()) {
channel.send(content);
}
return channel;
},
{ context: { channelID, content } }
);

return req?.find(res => !!res) || null;
};

0 comments on commit e7ed8d3

Please sign in to comment.