Skip to content

Commit 383d501

Browse files
authored
Added owo responses (#83)
1 parent 9da0ef4 commit 383d501

File tree

6 files changed

+77
-13
lines changed

6 files changed

+77
-13
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Threading.Tasks;
2+
using Qmmands;
3+
using static Espeon.LocalisationStringKey;
4+
5+
namespace Espeon {
6+
[Name("Responses")]
7+
[Description("Commands to configure how the bot communicates with you")]
8+
public class ResponseModule : EspeonCommandModule {
9+
public EspeonDbContext DbContext { get; set; }
10+
11+
[Name("owo")]
12+
[Command("owo")]
13+
[Description("Sets the bot to respond using owo responses")]
14+
public async Task OwoAsync() {
15+
await LocalisationService.UpdateLocalisationAsync(DbContext, Context.Guild.Id, Context.Member.Id, Language.Owo);
16+
await ReplyAsync(LOCALISATION_SET, "owo");
17+
}
18+
19+
[Name("Default")]
20+
[Command("default")]
21+
[Description("Sets the bot to respond using default responses")]
22+
public async Task DefaultAsync() {
23+
await LocalisationService.UpdateLocalisationAsync(DbContext, Context.Guild.Id, Context.Member.Id, Language.Default);
24+
await ReplyAsync(LOCALISATION_SET, "default");
25+
}
26+
}
27+
}

src/Localisation/LocalisationStringKey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public enum LocalisationStringKey {
1818
MEMBER_NOT_IN_GUILD,
1919
MEMBER_NOT_IN_CACHE_NO_MENTION,
2020
REMINDER_DELETED,
21-
MULTIPLE_MATCHING_REMINDERS
21+
MULTIPLE_MATCHING_REMINDERS,
22+
LOCALISATION_SET,
2223
}
2324
}

src/Localisation/default

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ REMINDER_PARSER_NO_TIMESPAN=A timespan in the future needs to be specified when
44
GUILDTAG_ALREADY_EXISTS="{0}" already exists for this guild
55
TAG_CREATED={0} has been created
66
TAG_DOESNT_EXIST="{0}" does not exist
7-
TAG_RESERVED_WORD="{0}" is a reserved word, cannot create a tag using it,
7+
TAG_RESERVED_WORD="{0}" is a reserved word, cannot create a tag using it
88
MUST_OWN_TAG=You must own this tag to remove it, currently, {0} owns it
99
TAG_DELETED="{0}" has been deleted
1010
INVALID_MESSAGE_ID_PATH=Could not find message given input
@@ -16,4 +16,5 @@ INVALID_PEPOWHATIF_SIZE=pepowhatif can only be size 0, 16, or 36
1616
MEMBER_NOT_IN_GUILD=Member was not found in this guild
1717
MEMBER_NOT_IN_CACHE_NO_MENTION=Member was not found in bot cache, try mentioning them
1818
REMINDER_DELETED=Reminder has been deleted
19-
MULTIPLE_MATCHING_REMINDERS=Multiple reminders match id "{0}" please contact your resident clown
19+
MULTIPLE_MATCHING_REMINDERS=Multiple reminders match id "{0}" please contact your resident clown
20+
LOCALISATION_SET=Localisation has been set to {0}

src/Localisation/owo

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
PING_COMMAND=pwong :3
2-
REMINDER_CREATED=wemwinder cweated xx
2+
REMINDER_CREATED=wemwinder cweated xx
3+
REMINDER_PARSER_NO_TIMESPAN=oooooo no!!! >>.<< twhe twimespwam needs 2 be in de furrture!
4+
GUILDTAG_ALREADY_EXISTS=😳 ooooooooooooooh nooooooooooooooooo!!!! {0} awredy eskswists!!
5+
TAG_CREATED=cweatid {0} xx
6+
TAG_DOESNT_EXIST=wat is dis {0}
7+
TAG_RESERVED_WORD=owoopsee daysee!! u cant use {0}
8+
MUST_OWN_TAG=wuh ooh {0} owns thwis!
9+
TAG_DELETED={0} has been wooshed!!!
10+
INVALID_MESSAGE_ID_PATH=me confoosed dis mweasage not exwists >.<
11+
MESSAGE_HAS_EMPTY_CONTENT=my dwev is wazy n he cba to wead embweds hehe
12+
MODULE_NOT_FOUND=me nono dis modwule
13+
NO_MATCHING_COMMANDS=uhoh me no fwind dose cwommands
14+
NO_REMINDERS_FOUND=404 wemders not fwound :3c!
15+
INVALID_PEPOWHATIF_SIZE=size cwn onwee be 0, 16, or 36!
16+
MEMBER_NOT_IN_GUILD=>>.<< dis pwerson not here!
17+
MEMBER_NOT_IN_CACHE_NO_MENTION=>>.<< dis pwerson not here! twy menshun
18+
REMINDER_DELETED=hahahaha! i dweted dat weminder
19+
MULTIPLE_MATCHING_REMINDERS=uuuuuh dis mwached multwiples weminders msg my cwown dev
20+
LOCALISATION_SET=sugoiiiiiiii :3c

src/Services/LocalisationService.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using Disqord;
2-
using Microsoft.Extensions.DependencyInjection;
3-
using Microsoft.Extensions.Hosting;
4-
using Microsoft.Extensions.Logging;
5-
using System;
1+
using System;
62
using System.Collections.Concurrent;
73
using System.Collections.Generic;
84
using System.Diagnostics;
95
using System.Threading;
106
using System.Threading.Tasks;
7+
using Disqord;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Hosting;
10+
using Microsoft.Extensions.Logging;
1111

1212
namespace Espeon {
1313
public class LocalisationService : IHostedService {
@@ -84,5 +84,22 @@ private string GetResponse(Language language, LocalisationStringKey stringKey, o
8484
public LocalisationStringKey GetKey(string str) {
8585
return this._localisationCache.GetOrAdd(str, Enum.Parse<LocalisationStringKey>);
8686
}
87+
88+
public async Task UpdateLocalisationAsync(
89+
EspeonDbContext context,
90+
ulong guildId,
91+
ulong userId,
92+
Language language) {
93+
var locale = await context.GetOrCreateAsync(
94+
guildId,
95+
userId,
96+
(guild, user) => new UserLocalisation(guild, user)
97+
);
98+
locale.Value = language;
99+
100+
this._userLanguageCache[(guildId, userId)] = language;
101+
102+
await context.UpdateAsync(locale);
103+
}
87104
}
88105
}

src/Services/ReminderService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class ReminderService : IOnReadyService {
1919
private readonly ConcurrentDictionary<ulong, HashSet<UserReminder>> _reminderByUserId;
2020

2121
public ReminderService(
22-
IServiceProvider services,
23-
EspeonScheduler scheduler,
24-
EspeonBot espeon,
25-
ILogger<ReminderService> logger) {
22+
IServiceProvider services,
23+
EspeonScheduler scheduler,
24+
EspeonBot espeon,
25+
ILogger<ReminderService> logger) {
2626
this._services = services;
2727
this._logger = logger;
2828
this._scheduler = scheduler;

0 commit comments

Comments
 (0)