Sharding over processes almost done
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Utility;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
public partial class Utility
|
||||
{
|
||||
[Group]
|
||||
public class CrossServerTextChannel : NadekoSubmodule
|
||||
{
|
||||
private readonly CrossServerTextService _service;
|
||||
|
||||
public CrossServerTextChannel(CrossServerTextService service)
|
||||
{
|
||||
_service = service;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Scsc()
|
||||
{
|
||||
var token = new NadekoRandom().Next();
|
||||
var set = new ConcurrentHashSet<ITextChannel>();
|
||||
if (_service.Subscribers.TryAdd(token, set))
|
||||
{
|
||||
set.Add((ITextChannel) Context.Channel);
|
||||
await ((IGuildUser) Context.User).SendConfirmAsync(GetText("csc_token"), token.ToString())
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequireUserPermission(GuildPermission.ManageGuild)]
|
||||
public async Task Jcsc(int token)
|
||||
{
|
||||
ConcurrentHashSet<ITextChannel> set;
|
||||
if (!_service.Subscribers.TryGetValue(token, out set))
|
||||
return;
|
||||
set.Add((ITextChannel) Context.Channel);
|
||||
await ReplyConfirmLocalized("csc_join").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequireUserPermission(GuildPermission.ManageGuild)]
|
||||
public async Task Lcsc()
|
||||
{
|
||||
foreach (var subscriber in _service.Subscribers)
|
||||
{
|
||||
subscriber.Value.TryRemove((ITextChannel) Context.Channel);
|
||||
}
|
||||
await ReplyConfirmLocalized("csc_leave").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,84 +35,7 @@ namespace NadekoBot.Modules.Utility
|
||||
_stats = stats;
|
||||
_creds = creds;
|
||||
_bot = bot;
|
||||
}
|
||||
|
||||
//[NadekoCommand, Usage, Description, Aliases]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Midorina([Remainder] string arg)
|
||||
//{
|
||||
// var channel = (ITextChannel)Context.Channel;
|
||||
|
||||
// var roleNames = arg?.Split(';');
|
||||
|
||||
// if (roleNames == null || roleNames.Length == 0)
|
||||
// return;
|
||||
|
||||
// var j = 0;
|
||||
// var roles = roleNames.Select(x => Context.Guild.Roles.FirstOrDefault(r => String.Compare(r.Name, x, StringComparison.OrdinalIgnoreCase) == 0))
|
||||
// .Where(x => x != null)
|
||||
// .Take(10)
|
||||
// .ToArray();
|
||||
|
||||
// var rnd = new NadekoRandom();
|
||||
// var reactions = new[] { "🎬", "🐧", "🌍", "🌺", "🚀", "☀", "🌲", "🍒", "🐾", "🏀" }
|
||||
// .OrderBy(x => rnd.Next())
|
||||
// .ToArray();
|
||||
|
||||
// var roleStrings = roles
|
||||
// .Select(x => $"{reactions[j++]} -> {x.Name}");
|
||||
|
||||
// var msg = await Context.Channel.SendConfirmAsync("Pick a Role",
|
||||
// string.Join("\n", roleStrings)).ConfigureAwait(false);
|
||||
|
||||
// for (int i = 0; i < roles.Length; i++)
|
||||
// {
|
||||
// try { await msg.AddReactionAsync(reactions[i]).ConfigureAwait(false); }
|
||||
// catch (Exception ex) { _log.Warn(ex); }
|
||||
// await Task.Delay(1000).ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// msg.OnReaction((r) => Task.Run(async () =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var usr = r.User.GetValueOrDefault() as IGuildUser;
|
||||
|
||||
// if (usr == null)
|
||||
// return;
|
||||
|
||||
// var index = Array.IndexOf<string>(reactions, r.Emoji.Name);
|
||||
// if (index == -1)
|
||||
// return;
|
||||
|
||||
// await usr.RemoveRolesAsync(roles[index]);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// _log.Warn(ex);
|
||||
// }
|
||||
// }), (r) => Task.Run(async () =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var usr = r.User.GetValueOrDefault() as IGuildUser;
|
||||
|
||||
// if (usr == null)
|
||||
// return;
|
||||
|
||||
// var index = Array.IndexOf<string>(reactions, r.Emoji.Name);
|
||||
// if (index == -1)
|
||||
// return;
|
||||
|
||||
// await usr.RemoveRolesAsync(roles[index]);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// _log.Warn(ex);
|
||||
// }
|
||||
// }));
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
Reference in New Issue
Block a user