-
Notifications
You must be signed in to change notification settings - Fork 3
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 #8 from nyxx-discord/feature/reminder
[feature] Reminder
- Loading branch information
Showing
18 changed files
with
517 additions
and
153 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Create and publish a Docker image | ||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
release: | ||
types: | ||
- created | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.TOKEN_PUSH_IMAGE }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.PHONY: help | ||
help: | ||
@fgrep -h "##" $(MAKEFILE_LIST) | sed -e 's/\(\:.*\#\#\)/\:\ /' | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | ||
|
||
.PHONY: build | ||
build: ## build images | ||
docker compose build | ||
|
||
.PHONY: build-no-cache | ||
build-no-cache: ## build images discarding cache | ||
docker compose build --no-cache | ||
|
||
.PHONY: stop | ||
stop: ## stop images | ||
docker compose down | ||
|
||
.PHONY: start | ||
start: build ## start images from docker compose | ||
docker compose up | ||
|
||
.PHONY: clean | ||
clean: stop ## clean container created by docker compose | ||
docker compose rm | ||
|
||
.PHONY: clean-start | ||
clean-start: clean build-no-cache start ## cleans cache, build discarding cache and start dockers |
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import "package:human_duration_parser/human_duration_parser.dart"; | ||
import "package:nyxx/nyxx.dart"; | ||
import "package:nyxx_commander/commander.dart"; | ||
import "package:running_on_dart/src/modules/reminder/reminder.dart"; | ||
|
||
Future<void> remainderCommand(CommandContext ctx, String content) async { | ||
final argString = ctx.getArguments().join(" "); | ||
|
||
if (argString.isEmpty) { | ||
await ctx.reply(MessageBuilder.content("Provide duration when remainder should be triggered")); | ||
return; | ||
} | ||
|
||
final triggerDate = DateTime.now().add(parseStringToDuration(argString)); | ||
final replyMessage = ctx.message.referencedMessage?.message?.url; | ||
|
||
if (replyMessage == null) { | ||
await ctx.reply(MessageBuilder.content("Reply to message to create remainder")); | ||
return; | ||
} | ||
|
||
final result = await createReminder(ctx.author.id, ctx.channel.id, triggerDate, replyMessage); | ||
|
||
if (result) { | ||
await ctx.reply(MessageBuilder.content("All right, <t:${triggerDate.millisecondsSinceEpoch ~/ 1000}:R> will remind about: $replyMessage")); | ||
return; | ||
} | ||
|
||
await ctx.reply(MessageBuilder.content("Internal server error. Report to developer")); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import "package:human_duration_parser/human_duration_parser.dart"; | ||
import "package:nyxx/nyxx.dart"; | ||
import "package:nyxx_interactions/interactions.dart"; | ||
import "package:running_on_dart/src/internal/utils.dart"; | ||
import "package:running_on_dart/src/modules/reminder/reminder.dart"; | ||
|
||
Future<void> reminderAddSlash(SlashCommandInteractionEvent event) async { | ||
await event.acknowledge(); | ||
|
||
final authorId = getAuthorId(event); | ||
|
||
final messageArg = event.getArg("message").value.toString(); | ||
final triggerAt = DateTime.now().add( | ||
parseStringToDuration(event.getArg("trigger-at").value.toString()) | ||
); | ||
|
||
final result = await createReminder( | ||
authorId, | ||
event.interaction.channel.id, | ||
triggerAt, | ||
messageArg | ||
); | ||
|
||
if (result) { | ||
return event.respond(MessageBuilder.content("All right, <t:${triggerAt.millisecondsSinceEpoch ~/ 1000}:R> will remind about: `$messageArg`")); | ||
} | ||
|
||
return event.respond(MessageBuilder.content("Internal server error. Report to developer")); | ||
} | ||
|
||
Future<void> remainderGetUsers(SlashCommandInteractionEvent event) async { | ||
await event.acknowledge(hidden: true); | ||
|
||
final authorId = event.interaction.guild?.id != null | ||
? event.interaction.memberAuthor!.id | ||
: event.interaction.userAuthor!.id; | ||
|
||
final remainders = fetchRemaindersForUser(authorId); | ||
|
||
if (remainders.isEmpty) { | ||
return event.respond(MessageBuilder.content("You dont have any remainders at the moment")); | ||
} | ||
|
||
final stringBuffer = StringBuffer("Your current remainders:\n"); | ||
for (final remainder in remainders) { | ||
stringBuffer.writeln("- [ID: ${remainder.id}] <t:${remainder.triggerDate.millisecondsSinceEpoch ~/ 1000}:R> - ${remainder.message}\n"); | ||
} | ||
stringBuffer.writeln("Remainders are cached for 30s. This could not be complete list of all remainders"); | ||
|
||
await event.respond(MessageBuilder.content(stringBuffer.toString()), hidden: true); | ||
} | ||
|
||
Future<void> remaindersClear(SlashCommandInteractionEvent event) async { | ||
await event.acknowledge(hidden: true); | ||
|
||
final authorId = getAuthorId(event); | ||
|
||
final result = await clearRemaindersForUser(authorId); | ||
return event.respond(MessageBuilder.content("Deleted $result remainders")); | ||
} | ||
|
||
Future<void> remainderRemove(SlashCommandInteractionEvent event) async { | ||
await event.acknowledge(hidden: true); | ||
|
||
final authorId = getAuthorId(event); | ||
final id = event.getArg("id").value as int; | ||
|
||
final result = await removeRemainderForUser(id, authorId); | ||
if (!result) { | ||
return event.respond(MessageBuilder.content("There was an problem deleting your remainder")); | ||
} | ||
|
||
return event.respond(MessageBuilder.content("Removed remainder with id: $id")); | ||
} |
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
Oops, something went wrong.