Added .boost, .boostmsg and .boostdel commands which allow you to have customizable messages when someone boosts your server, with auto-deletion support

- Updated response embed colors in greet commands
- Updated .greetmsg and .byemsg command help to match the new .boost command help
This commit is contained in:
Kwoth
2021-09-12 20:44:19 +02:00
parent a27ea7a0aa
commit 8ee1160a00
13 changed files with 2929 additions and 21 deletions

View File

@@ -7,11 +7,24 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
### Added
- `.rero` now optionally takes a message id to which to attach the reaction roles
- Fully translated to German 🎉
- Added `.boost`, `.boostmsg` and `.boostdel` commands which allow you to have customizable messages when someone boosts your server, with auto-deletion support
### Changed
- Updated `.greetmsg` and `.byemsg` command help to match the new `.boost` command help
- Updated response embed colors in greet commands
- Success -> green
- Warning or Disable -> yellow.
### Fixed
- `.timely` will now correctly use `Ok` color
### Removed
- Removed `.novel` command as it no longer works
## [3.0.1] - 10.09.2021
### Fixed

View File

@@ -29,6 +29,15 @@ namespace NadekoBot.Services.Database.Models
public bool SendChannelGreetMessage { get; set; }
public string ChannelGreetMessageText { get; set; } = "Welcome to the %server% server, %user%!";
#region Boost Message
public bool SendBoostMessage { get; set; }
public string BoostMessage { get; set; } = "%user% just boosted this server!";
public ulong BoostMessageChannelId { get; set; }
public int BoostMessageDeleteAfter { get; set; }
#endregion
public bool SendChannelByeMessage { get; set; }
public string ChannelByeMessageText { get; set; } = "%user% has left!";

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,56 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class boostmessages : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "BoostMessage",
table: "GuildConfigs",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<ulong>(
name: "BoostMessageChannelId",
table: "GuildConfigs",
type: "INTEGER",
nullable: false,
defaultValue: 0ul);
migrationBuilder.AddColumn<int>(
name: "BoostMessageDeleteAfter",
table: "GuildConfigs",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<bool>(
name: "SendBoostMessage",
table: "GuildConfigs",
type: "INTEGER",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "BoostMessage",
table: "GuildConfigs");
migrationBuilder.DropColumn(
name: "BoostMessageChannelId",
table: "GuildConfigs");
migrationBuilder.DropColumn(
name: "BoostMessageDeleteAfter",
table: "GuildConfigs");
migrationBuilder.DropColumn(
name: "SendBoostMessage",
table: "GuildConfigs");
}
}
}

View File

@@ -741,6 +741,15 @@ namespace NadekoBot.Migrations
b.Property<bool>("AutoDeleteSelfAssignedRoleMessages")
.HasColumnType("INTEGER");
b.Property<string>("BoostMessage")
.HasColumnType("TEXT");
b.Property<ulong>("BoostMessageChannelId")
.HasColumnType("INTEGER");
b.Property<int>("BoostMessageDeleteAfter")
.HasColumnType("INTEGER");
b.Property<ulong>("ByeMessageChannelId")
.HasColumnType("INTEGER");
@@ -801,6 +810,9 @@ namespace NadekoBot.Migrations
b.Property<string>("Prefix")
.HasColumnType("TEXT");
b.Property<bool>("SendBoostMessage")
.HasColumnType("INTEGER");
b.Property<bool>("SendChannelByeMessage")
.HasColumnType("INTEGER");

View File

@@ -12,6 +12,53 @@ namespace NadekoBot.Modules.Administration
[Group]
public class ServerGreetCommands : NadekoSubmodule<GreetSettingsService>
{
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageGuild)]
public async Task Boost()
{
var enabled = await _service.ToggleBoost(ctx.Guild.Id, ctx.Channel.Id);
if (enabled)
await ReplyConfirmLocalizedAsync(strs.boost_on).ConfigureAwait(false);
else
await ReplyPendingLocalizedAsync(strs.boost_off).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageGuild)]
public async Task BoostDel(int timer = 30)
{
if (timer < 0 || timer > 600)
return;
await _service.SetBoostDel(ctx.Guild.Id, timer);
if (timer > 0)
await ReplyConfirmLocalizedAsync(strs.boostdel_on(timer));
else
await ReplyPendingLocalizedAsync(strs.boostdel_off).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageGuild)]
public async Task BoostMsg([Leftover] string text)
{
if (string.IsNullOrWhiteSpace(text))
{
await GreetMsg().ConfigureAwait(false);
return;
}
var sendBoostEnabled = _service.SetBoostMessage(ctx.Guild.Id, ref text);
await ReplyConfirmLocalizedAsync(strs.boostmsg_new).ConfigureAwait(false);
if (!sendBoostEnabled)
await ReplyPendingLocalizedAsync(strs.boostmsg_enable($"`{Prefix}boost`"));
}
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageGuild)]
@@ -23,9 +70,9 @@ namespace NadekoBot.Modules.Administration
await _service.SetGreetDel(ctx.Guild.Id, timer).ConfigureAwait(false);
if (timer > 0)
await ReplyErrorLocalizedAsync(strs.greetdel_on(timer));
await ReplyConfirmLocalizedAsync(strs.greetdel_on(timer));
else
await ReplyConfirmLocalizedAsync(strs.greetdel_off).ConfigureAwait(false);
await ReplyPendingLocalizedAsync(strs.greetdel_off).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
@@ -38,7 +85,7 @@ namespace NadekoBot.Modules.Administration
if (enabled)
await ReplyConfirmLocalizedAsync(strs.greet_on).ConfigureAwait(false);
else
await ReplyConfirmLocalizedAsync(strs.greet_off).ConfigureAwait(false);
await ReplyPendingLocalizedAsync(strs.greet_off).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
@@ -46,8 +93,8 @@ namespace NadekoBot.Modules.Administration
[UserPerm(GuildPerm.ManageGuild)]
public Task GreetMsg()
{
string greetMsg = _service.GetGreetMsg(ctx.Guild.Id);
return ReplyErrorLocalizedAsync(strs.greetmsg_cur(greetMsg?.SanitizeMentions()));
var greetMsg = _service.GetGreetMsg(ctx.Guild.Id);
return ReplyConfirmLocalizedAsync(strs.greetmsg_cur(greetMsg?.SanitizeMentions()));
}
[NadekoCommand, Aliases]
@@ -65,7 +112,7 @@ namespace NadekoBot.Modules.Administration
await ReplyConfirmLocalizedAsync(strs.greetmsg_new).ConfigureAwait(false);
if (!sendGreetEnabled)
await ReplyErrorLocalizedAsync(strs.greetmsg_enable($"`{Prefix}greet`"));
await ReplyPendingLocalizedAsync(strs.greetmsg_enable($"`{Prefix}greet`"));
}
[NadekoCommand, Aliases]
@@ -87,7 +134,7 @@ namespace NadekoBot.Modules.Administration
public Task GreetDmMsg()
{
var dmGreetMsg = _service.GetDmGreetMsg(ctx.Guild.Id);
return ReplyErrorLocalizedAsync(strs.greetdmmsg_cur(dmGreetMsg?.SanitizeMentions()));
return ReplyConfirmLocalizedAsync(strs.greetdmmsg_cur(dmGreetMsg?.SanitizeMentions()));
}
[NadekoCommand, Aliases]
@@ -105,7 +152,7 @@ namespace NadekoBot.Modules.Administration
await ReplyConfirmLocalizedAsync(strs.greetdmmsg_new).ConfigureAwait(false);
if (!sendGreetEnabled)
await ReplyErrorLocalizedAsync(strs.greetdmmsg_enable($"`{Prefix}greetdm`"));
await ReplyPendingLocalizedAsync(strs.greetdmmsg_enable($"`{Prefix}greetdm`"));
}
[NadekoCommand, Aliases]
@@ -127,7 +174,7 @@ namespace NadekoBot.Modules.Administration
public Task ByeMsg()
{
var byeMsg = _service.GetByeMessage(ctx.Guild.Id);
return ReplyErrorLocalizedAsync(strs.byemsg_cur(byeMsg?.SanitizeMentions()));
return ReplyConfirmLocalizedAsync(strs.byemsg_cur(byeMsg?.SanitizeMentions()));
}
[NadekoCommand, Aliases]
@@ -145,7 +192,7 @@ namespace NadekoBot.Modules.Administration
await ReplyConfirmLocalizedAsync(strs.byemsg_new).ConfigureAwait(false);
if (!sendByeEnabled)
await ReplyErrorLocalizedAsync(strs.byemsg_enable($"`{Prefix}bye`"));
await ReplyPendingLocalizedAsync(strs.byemsg_enable($"`{Prefix}bye`"));
}
[NadekoCommand, Aliases]
@@ -156,9 +203,9 @@ namespace NadekoBot.Modules.Administration
await _service.SetByeDel(ctx.Guild.Id, timer).ConfigureAwait(false);
if (timer > 0)
await ReplyErrorLocalizedAsync(strs.byedel_on(timer));
await ReplyConfirmLocalizedAsync(strs.byedel_on(timer));
else
await ReplyConfirmLocalizedAsync(strs.byedel_off).ConfigureAwait(false);
await ReplyPendingLocalizedAsync(strs.byedel_off).ConfigureAwait(false);
}
@@ -174,7 +221,7 @@ namespace NadekoBot.Modules.Administration
var enabled = _service.GetByeEnabled(ctx.Guild.Id);
if (!enabled)
{
await ReplyErrorLocalizedAsync(strs.byemsg_enable($"`{Prefix}bye`"));
await ReplyPendingLocalizedAsync(strs.byemsg_enable($"`{Prefix}bye`"));
}
}
@@ -190,7 +237,7 @@ namespace NadekoBot.Modules.Administration
var enabled = _service.GetGreetEnabled(ctx.Guild.Id);
if (!enabled)
{
await ReplyErrorLocalizedAsync(strs.greetmsg_enable($"`{Prefix}greet`"));
await ReplyPendingLocalizedAsync(strs.greetmsg_enable($"`{Prefix}greet`"));
}
}
@@ -210,7 +257,7 @@ namespace NadekoBot.Modules.Administration
await ctx.WarningAsync();
var enabled = _service.GetGreetDmEnabled(ctx.Guild.Id);
if (!enabled)
await ReplyErrorLocalizedAsync(strs.greetdmmsg_enable($"`{Prefix}greetdm`"));
await ReplyPendingLocalizedAsync(strs.greetdmmsg_enable($"`{Prefix}greetdm`"));
}
}
}

View File

@@ -163,7 +163,7 @@ namespace NadekoBot.Modules.NSFW
{
if (!_service.AutoBoobTimers.TryRemove(ctx.Channel.Id, out t)) return;
t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer
t.Change(Timeout.Infinite, Timeout.Infinite);
await ReplyConfirmLocalizedAsync(strs.stopped).ConfigureAwait(false);
return;
}

View File

@@ -50,7 +50,6 @@ namespace NadekoBot.Modules.Searches.Services
}
}
// todo fix novel
public async Task<NovelResult> GetNovelData(string query)
{
if (string.IsNullOrWhiteSpace(query))

View File

@@ -48,8 +48,51 @@ namespace NadekoBot.Services
bot.JoinedGuild += Bot_JoinedGuild;
_client.LeftGuild += _client_LeftGuild;
_client.GuildMemberUpdated += ClientOnGuildMemberUpdated;
}
private Task ClientOnGuildMemberUpdated(SocketGuildUser oldUser, SocketGuildUser newUser)
{
if (oldUser is { PremiumSince: null } && newUser is { PremiumSince: not null })
{
var conf = GetOrAddSettingsForGuild(newUser.Guild.Id);
if (!conf.SendBoostMessage) return Task.CompletedTask;
_ = Task.Run(TriggerBoostMessage(conf, newUser));
}
return Task.CompletedTask;
}
private Func<Task> TriggerBoostMessage(GreetSettings conf, SocketGuildUser user) => async () =>
{
var channel = user.Guild.GetTextChannel(conf.BoostMessageChannelId);
if (channel is null)
return;
if (string.IsNullOrWhiteSpace(conf.BoostMessage))
return;
var toSend = SmartText.CreateFrom(conf.BoostMessage);
var rep = new ReplacementBuilder()
.WithDefault(user, channel, user.Guild, _client)
.Build();
try
{
var toDelete = await channel.SendAsync(rep.Replace(toSend));
if (conf.BoostMessageDeleteAfter > 0)
{
toDelete.DeleteAfter(conf.BoostMessageDeleteAfter);
}
}
catch (Exception ex)
{
Log.Error(ex, "Error sending boost message.");
}
};
private Task _client_LeftGuild(SocketGuild arg)
{
GuildConfigsCache.TryRemove(arg.Id, out _);
@@ -524,6 +567,48 @@ namespace NadekoBot.Services
await uow.SaveChangesAsync();
}
}
public bool SetBoostMessage(ulong guildId, ref string message)
{
message = message?.SanitizeMentions();
using var uow = _db.GetDbContext();
var conf = uow.GuildConfigsForId(guildId, set => set);
conf.BoostMessage = message;
var toAdd = GreetSettings.Create(conf);
GuildConfigsCache.AddOrUpdate(guildId, toAdd,(_, _) => toAdd);
uow.SaveChanges();
return conf.SendBoostMessage;
}
public async Task SetBoostDel(ulong guildId, int timer)
{
if (timer < 0 || timer > 600)
throw new ArgumentOutOfRangeException(nameof(timer));
using var uow = _db.GetDbContext();
var conf = uow.GuildConfigsForId(guildId, set => set);
conf.BoostMessageDeleteAfter = timer;
var toAdd = GreetSettings.Create(conf);
GuildConfigsCache.AddOrUpdate(guildId, toAdd,(_, _) => toAdd);
await uow.SaveChangesAsync();
}
public async Task<bool> ToggleBoost(ulong guildId, ulong channelId)
{
using var uow = _db.GetDbContext();
var conf = uow.GuildConfigsForId(guildId, set => set);
conf.SendBoostMessage = !conf.SendBoostMessage;
await uow.SaveChangesAsync();
var toAdd = GreetSettings.Create(conf);
GuildConfigsCache.AddOrUpdate(guildId, toAdd,(_, _) => toAdd);
return conf.SendBoostMessage;
}
}
public class GreetSettings
@@ -542,6 +627,11 @@ namespace NadekoBot.Services
public bool SendChannelByeMessage { get; set; }
public string ChannelByeMessageText { get; set; }
public bool SendBoostMessage { get; set; }
public string BoostMessage { get; set; }
public int BoostMessageDeleteAfter { get; set; }
public ulong BoostMessageChannelId { get; set; }
public static GreetSettings Create(GuildConfig g) => new GreetSettings()
{
@@ -555,6 +645,11 @@ namespace NadekoBot.Services
ChannelGreetMessageText = g.ChannelGreetMessageText,
SendChannelByeMessage = g.SendChannelByeMessage,
ChannelByeMessageText = g.ChannelByeMessageText,
SendBoostMessage = g.SendBoostMessage,
BoostMessage = g.BoostMessage,
BoostMessageDeleteAfter = g.BoostMessageDeleteAfter,
BoostMessageChannelId = g.BoostMessageChannelId
};
}
}

View File

@@ -12,8 +12,6 @@ using NadekoBot.Modules.Administration;
namespace NadekoBot.Services
{
// todo future use guild locale more in the code (from guild settings) (for dates, currency, etc?)
// todo future maybe Write a sourcegen for response strings
// and use const/static fields (maybe even typed to enforce correct number of arguments)
public class Localization : ILocalization, INService
{
private readonly BotConfigService _bss;

View File

@@ -32,6 +32,12 @@ greetdmtest:
- greetdmtest
byetest:
- byetest
boost:
- boost
boostmsg:
- boostmsg
boostdel:
- boostdel
logserver:
- logserver
logignore:

View File

@@ -31,7 +31,12 @@ greet:
args:
- ""
greetmsg:
desc: "Sets a new join announcement message which will be shown in the server's channel. Type `%user.mention%` if you want to mention the new member. Using it with no message will show the current greet message. You can use embed json from <https://eb.nadeko.bot/> instead of a regular text, if you want the message to be embedded."
desc: |-
Sets a new join announcement message which will be shown in the server's channel.
Type `%user.mention%` if you want to mention the new member.
Full list of placeholders can be found here <https://nadekobot.readthedocs.io/en/latest/placeholders/>
Using it with no message will show the current greet message.
You can use embed json from <https://eb.nadeko.bot/> instead of a regular text, if you want the message to be embedded.
args:
- "Welcome, %user.mention%."
bye:
@@ -39,7 +44,12 @@ bye:
args:
- ""
byemsg:
desc: "Sets a new leave announcement message. Type `%user.mention%` if you want to show the name the user who left. Type `%id%` to show id. Using this command with no message will show the current bye message. You can use embed json from <https://eb.nadeko.bot/> instead of a regular text, if you want the message to be embedded."
desc: |-
Sets a new leave announcement message.
Type `%user.mention%` if you want to show the name the user who left.
Full list of placeholders can be found here <https://nadekobot.readthedocs.io/en/latest/placeholders/>
Using this command with no message will show the current bye message.
You can use embed json from <https://eb.nadeko.bot/> instead of a regular text, if you want the message to be embedded.
args:
- "%user.mention% has left."
byedel:
@@ -66,6 +76,24 @@ byetest:
args:
- ""
- "@SomeoneElse"
boost:
desc: "Toggles anouncements on the current channel when someone boosts the server."
args:
- ""
boostmsg:
desc: |-
Sets a new boost announcement message.
Type `%user.mention%` if you want to show the name the user who left.
Full list of placeholders can be found here <https://nadekobot.readthedocs.io/en/latest/placeholders/>
Using this command with no message will show the current boost message.
You can use embed json from <https://eb.nadeko.bot/> instead of a regular text, if you want the message to be embedded.
args:
- "%user.mention% has boosted the server!!!"
boostdel:
desc: "Sets the time it takes (in seconds) for boost messages to be auto-deleted. Set it to `0` to disable automatic deletion."
args:
- "0"
- "30"
logserver:
desc: "Enables or Disables ALL log events. If enabled, all log events will log to this channel."
args:

View File

@@ -69,6 +69,13 @@
"greetmsg_new": "New greet message set.",
"greet_off": "Greet announcements disabled.",
"greet_on": "Greet announcements enabled on this channel.",
"boost_on": "Boost announcements enabled on this channel.",
"boost_off": "Boost announcements disabled.",
"boostmsg_cur": "Current boost message: {0}",
"boostmsg_enable": "Enable boost messages by typing {0}",
"boostmsg_new": "New boost message set.",
"boostdel_off": "Automatic deletion of boost messages has been disabled.",
"boostdel_on": "Boost messages will be deleted after {0} seconds.",
"hierarchy": "You can't use this command on users with a role higher or equal than yours (or mine) in the role hierarchy.",
"role_too_high": "You can't use this command with roles which are above your highest role, unless you're server administrator.",
"images_loading": "Images will be reloaded within a few seconds.",