Initial example with 2 commands of the new permission system
This commit is contained in:
@@ -8,6 +8,8 @@ using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Services;
|
||||
using Discord;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
@@ -24,7 +26,18 @@ namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
await channel.SendMessageAsync($"{command.Text} {action.Value} {user}");
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
uow.GuildConfigs.For(channel.Guild.Id).Permissions.Add(new Permission
|
||||
{
|
||||
TargetType = PermissionType.User,
|
||||
Target = user.Id.ToString(),
|
||||
Command = command.Text.ToLowerInvariant(),
|
||||
State = action.Value,
|
||||
});
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{user}` user.");
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
@@ -33,7 +46,18 @@ namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
await channel.SendMessageAsync($"{module.Name} {action.Value} {user}");
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
uow.GuildConfigs.For(channel.Guild.Id).Permissions.Add(new Permission
|
||||
{
|
||||
TargetType = PermissionType.User,
|
||||
Target = user.Id.ToString(),
|
||||
Module = module.Name.ToLowerInvariant(),
|
||||
State = action.Value,
|
||||
});
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{user}` user.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -101,7 +101,7 @@ namespace NadekoBot.Modules.Searches
|
||||
cachedStatuses.TryAdd(hitboxUrl, result);
|
||||
return result;
|
||||
case FollowedStream.FollowedStreamType.Twitch:
|
||||
var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}";
|
||||
var twitchUrl = $"https://api.twitch.tv/kraken/streams/{Uri.EscapeUriString(stream.Username)}?client_id=67w6z9i09xv2uoojdm9l0wsyph4hxo6";
|
||||
if (checkCache && cachedStatuses.TryGetValue(twitchUrl, out result))
|
||||
return result;
|
||||
using (var http = new HttpClient())
|
||||
@@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Searches
|
||||
}
|
||||
data = JObject.Parse(response);
|
||||
isLive = !string.IsNullOrWhiteSpace(data["stream"].ToString());
|
||||
result = new Tuple<bool, string>(isLive, isLive ? data["stream"]["viewers"].ToString() : "0");
|
||||
result = new Tuple<bool, string>(isLive, isLive ? data["stream"]["viewers"].ToString() : stream.Username);
|
||||
cachedStatuses.TryAdd(twitchUrl, result);
|
||||
return result;
|
||||
case FollowedStream.FollowedStreamType.Beam:
|
||||
@@ -225,7 +225,11 @@ namespace NadekoBot.Modules.Searches
|
||||
}));
|
||||
if (streamStatus.Item1)
|
||||
{
|
||||
await channel.SendMessageAsync($"`Streamer {streamStatus.Item2} is online.`");
|
||||
await channel.SendMessageAsync($"`Streamer {username} is online with {streamStatus.Item2}.`");
|
||||
}
|
||||
else
|
||||
{
|
||||
await channel.SendMessageAsync($"`Streamer {username} is offline.`");
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
Reference in New Issue
Block a user