mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ab0fd44b46 | ||
|
b61f499f91 | ||
|
53d365db3a | ||
|
140c4f7fd6 | ||
|
5627a3b172 | ||
|
4795fa98a0 | ||
|
93453ba522 | ||
|
c6a9108474 | ||
|
c3ba805acf | ||
|
c0ce22a6b7 | ||
|
22183501fe | ||
|
2fbdab3235 |
@@ -2,7 +2,14 @@
|
||||
|
||||
Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o
|
||||
|
||||
## [3.0.12] = 06.01.2021
|
||||
## [3.0.13] - 14.04.2021
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.greetdm` causing ratelimits during raids
|
||||
- Fixed `.gelbooru`
|
||||
|
||||
## [3.0.12] - 06.01.2021
|
||||
|
||||
### Fixed
|
||||
- `.smch` Fixed
|
||||
|
@@ -4,6 +4,19 @@
|
||||
|
||||
#### [Linux migration instructions](../migration-guide/#linux)
|
||||
|
||||
#### Operating System Compatibility
|
||||
|
||||
It is recommended that you use **Ubuntu 20.04**, as there have been nearly no problems with it. Also, **32-bit systems are incompatible**.
|
||||
|
||||
##### Compatible operating systems:
|
||||
|
||||
- Ubuntu: 16.04, 18.04, 20.04, 21.04, 21.10
|
||||
- Mint: 19, 20
|
||||
- Debian: 9, 10
|
||||
- CentOS: 7
|
||||
- openSUSE
|
||||
- Fedora: 33, 34, 35
|
||||
|
||||
## Linux From Source
|
||||
|
||||
Open Terminal (if you're on an installation with a window manager) and navigate to the location where you want to install the bot (for example `cd ~`)
|
||||
@@ -34,6 +47,8 @@ Open Terminal (if you're on an installation with a window manager) and navigate
|
||||
|
||||
## Linux Release
|
||||
|
||||
⚠ IF YOU ARE FOLLOWING THE GUIDE ABOVE, IGNORE THIS SECTION ⚠
|
||||
|
||||
##### Installation Instructions
|
||||
|
||||
1. Download the latest release from <https://gitlab.com/Kwoth/nadekobot/-/releases>
|
||||
|
@@ -56,6 +56,8 @@ sudo ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
|
||||
|
||||
## MacOS Manual Release installation instructions
|
||||
|
||||
⚠ IF YOU ARE FOLLOWING THE GUIDE ABOVE, IGNORE THIS SECTION ⚠
|
||||
|
||||
##### Installation Instructions
|
||||
|
||||
1. Download the latest release from <https://gitlab.com/Kwoth/nadekobot/-/releases>
|
||||
@@ -120,4 +122,4 @@ rm -r nadekobot-old/data/strings && \
|
||||
cp -RT nadekobot-old/data/ nadekobot/data/ && \
|
||||
cp nadekobot-old/creds.yml nadekobot/ && \
|
||||
cd nadekobot && chmod +x NadekoBot
|
||||
```
|
||||
```
|
||||
|
@@ -69,6 +69,8 @@ You can still install them manually:
|
||||
|
||||
### Windows From Source
|
||||
|
||||
⚠ IF YOU ARE FOLLOWING THE GUIDE ABOVE, IGNORE THIS SECTION ⚠
|
||||
|
||||
##### Prerequisites
|
||||
|
||||
**Install these before proceeding or your bot will not work!**
|
||||
|
@@ -258,8 +258,7 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
user = user ?? (IGuildUser) ctx.User;
|
||||
|
||||
var channel = await user.GetOrCreateDMChannelAsync();
|
||||
var success = await _service.GreetDmTest(channel, user);
|
||||
var success = await _service.GreetDmTest(user);
|
||||
if (success)
|
||||
await ctx.OkAsync();
|
||||
else
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -13,10 +14,11 @@ namespace NadekoBot.Modules.Nsfw.Common
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page, bool isExplicit = false, CancellationToken cancel = default)
|
||||
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page,
|
||||
bool isExplicit = false, CancellationToken cancel = default)
|
||||
{
|
||||
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
|
||||
var uri = $"http://gelbooru.com/index.php?page=dapi&s=post&json=1&q=index&limit=100" +
|
||||
var uri = $"https://gelbooru.com/index.php?page=dapi&s=post&json=1&q=index&limit=100" +
|
||||
$"&tags={tagString}&pid={page}";
|
||||
using var req = new HttpRequestMessage(HttpMethod.Get, uri);
|
||||
using var res = await _http.SendAsync(req, cancel).ConfigureAwait(false);
|
||||
@@ -24,12 +26,18 @@ namespace NadekoBot.Modules.Nsfw.Common
|
||||
var resString = await res.Content.ReadAsStringAsync(cancel);
|
||||
if (string.IsNullOrWhiteSpace(resString))
|
||||
return new();
|
||||
|
||||
var images = JsonSerializer.Deserialize<List<DapiImageObject>>(resString, _serializerOptions);
|
||||
if (images is null)
|
||||
|
||||
var images = JsonSerializer.Deserialize<GelbooruResponse>(resString, _serializerOptions);
|
||||
if (images is null or { Post: null })
|
||||
return new();
|
||||
|
||||
return images.Where(x => x.FileUrl is not null).ToList();
|
||||
return images.Post.Where(x => x.FileUrl is not null).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public class GelbooruResponse
|
||||
{
|
||||
[JsonPropertyName("post")]
|
||||
public List<DapiImageObject> Post { get; set; }
|
||||
}
|
||||
}
|
@@ -4,7 +4,9 @@ using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Modules.Utility.Common.Patreon;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@@ -146,15 +148,22 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
if (DateTime.UtcNow.Day < 5)
|
||||
return;
|
||||
|
||||
// if the user has the necessary patreon creds
|
||||
// and the access token expired or doesn't exist
|
||||
// -> update access token
|
||||
if (!HasPatreonCreds(creds))
|
||||
if (string.IsNullOrWhiteSpace(creds.Patreon.CampaignId))
|
||||
return;
|
||||
|
||||
if (LastAccessTokenUpdate(creds).Month < DateTime.UtcNow.Month
|
||||
var lastUpdate = LastAccessTokenUpdate(creds);
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
if (lastUpdate.Year != now.Year
|
||||
|| lastUpdate.Month != now.Month
|
||||
|| string.IsNullOrWhiteSpace(creds.Patreon.AccessToken))
|
||||
{
|
||||
// if the user has the necessary patreon creds
|
||||
// and the access token expired or doesn't exist
|
||||
// -> update access token
|
||||
if (!HasPatreonCreds(creds))
|
||||
return;
|
||||
|
||||
var success = await UpdateAccessToken(creds);
|
||||
if (!success)
|
||||
return;
|
||||
@@ -164,7 +173,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
await getPledgesLocker.WaitAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
var members = new List<PatreonMember>();
|
||||
var users = new List<PatreonUser>();
|
||||
using (var http = _httpFactory.CreateClient())
|
||||
@@ -185,7 +194,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
|
||||
if (data is null)
|
||||
break;
|
||||
|
||||
|
||||
members.AddRange(data.Data);
|
||||
users.AddRange(data.Included);
|
||||
} while (!string.IsNullOrWhiteSpace(page = data?.Links?.Next));
|
||||
@@ -209,12 +218,19 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
EntitledTo: > 0
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
foreach (var pledge in userData)
|
||||
{
|
||||
await ClaimReward(pledge.UserId, pledge.PatreonUserId, pledge.EntitledTo);
|
||||
}
|
||||
}
|
||||
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
Log.Warning("Patreon credentials invalid or expired. I will try to refresh them during the next run");
|
||||
var db = _redis.GetDatabase();
|
||||
await db.KeyDeleteAsync($"{creds.RedisKey()}_patreon_update");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Error refreshing patreon pledges");
|
||||
@@ -223,7 +239,6 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
getPledgesLocker.Release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<int> ClaimReward(ulong userId, string patreonUserId, int cents)
|
||||
|
@@ -8,14 +8,16 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Modules.Administration;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
public class GreetSettingsService : INService
|
||||
public class GreetSettingsService : INService, IReadyExecutor
|
||||
{
|
||||
private readonly DbService _db;
|
||||
|
||||
@@ -51,6 +53,17 @@ namespace NadekoBot.Services
|
||||
|
||||
_client.GuildMemberUpdated += ClientOnGuildMemberUpdated;
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var (conf, user, compl) = await _greetDmQueue.Reader.ReadAsync();
|
||||
var res = await GreetDmUserInternal(conf, user);
|
||||
compl.TrySetResult(res);
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
private Task ClientOnGuildMemberUpdated(SocketGuildUser oldUser, SocketGuildUser newUser)
|
||||
{
|
||||
@@ -240,16 +253,33 @@ namespace NadekoBot.Services
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> GreetDmUser(GreetSettings conf, IDMChannel channel, IGuildUser user)
|
||||
private readonly Channel<(GreetSettings, IGuildUser, TaskCompletionSource<bool>)> _greetDmQueue =
|
||||
Channel.CreateBounded<(GreetSettings, IGuildUser, TaskCompletionSource<bool>)>(new BoundedChannelOptions(60)
|
||||
{
|
||||
// The limit of 60 users should be only hit when there's a raid. In that case
|
||||
// probably the best thing to do is to drop newest (raiding) users
|
||||
FullMode = BoundedChannelFullMode.DropNewest
|
||||
});
|
||||
|
||||
private async Task<bool> GreetDmUser(GreetSettings conf, IGuildUser user)
|
||||
{
|
||||
var completionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
await _greetDmQueue.Writer.WriteAsync((conf, user, completionSource));
|
||||
return await completionSource.Task;
|
||||
}
|
||||
|
||||
private async Task<bool> GreetDmUserInternal(GreetSettings conf, IGuildUser user)
|
||||
{
|
||||
var rep = new ReplacementBuilder()
|
||||
.WithDefault(user, channel, (SocketGuild)user.Guild, _client)
|
||||
.Build();
|
||||
|
||||
var text = SmartText.CreateFrom(conf.DmGreetMessageText);
|
||||
rep.Replace(text);
|
||||
try
|
||||
{
|
||||
var rep = new ReplacementBuilder()
|
||||
.WithUser(user)
|
||||
.WithServer(_client, (SocketGuild)user.Guild)
|
||||
.Build();
|
||||
|
||||
var text = SmartText.CreateFrom(conf.DmGreetMessageText);
|
||||
text = rep.Replace(text);
|
||||
|
||||
if (text is SmartPlainText pt)
|
||||
{
|
||||
text = new SmartEmbedText() { PlainText = pt.Text };
|
||||
@@ -259,8 +289,12 @@ namespace NadekoBot.Services
|
||||
{
|
||||
Text = $"This message was sent from {user.Guild} server.", IconUrl = user.Guild.IconUrl
|
||||
};
|
||||
|
||||
var ch = await user.GetOrCreateDMChannelAsync();
|
||||
if (ch is null)
|
||||
return false;
|
||||
|
||||
await channel.SendAsync(text).ConfigureAwait(false);
|
||||
await ch.SendAsync(text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -311,12 +345,7 @@ namespace NadekoBot.Services
|
||||
|
||||
if (conf.SendDmGreetMessage)
|
||||
{
|
||||
var channel = await user.GetOrCreateDMChannelAsync().ConfigureAwait(false);
|
||||
|
||||
if (channel != null)
|
||||
{
|
||||
await GreetDmUser(conf, channel, user);
|
||||
}
|
||||
await GreetDmUser(conf, user);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -487,10 +516,10 @@ namespace NadekoBot.Services
|
||||
return GreetUsers(conf, channel, user);
|
||||
}
|
||||
|
||||
public Task<bool> GreetDmTest(IDMChannel channel, IGuildUser user)
|
||||
public Task<bool> GreetDmTest(IGuildUser user)
|
||||
{
|
||||
var conf = GetOrAddSettingsForGuild(user.GuildId);
|
||||
return GreetDmUser(conf, channel, user);
|
||||
return GreetDmUser(conf, user);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
Reference in New Issue
Block a user