本文整理汇总了C#中Discord.User类的典型用法代码示例。如果您正苦于以下问题:C# User类的具体用法?C# User怎么用?C# User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
User类属于Discord命名空间,在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MuteUser
async Task MuteUser(Server server, Channel channel, User user, DateTime expiresOn)
{
try
{
// TODO: need to check if client has permissions and user is not the owner
var mutedRole = server.Roles.SingleOrDefault(r => r.Name == "Muted")
?? await CreateMutedRole(server);
var punishment = new Punishment
{
Id = Guid.NewGuid(),
Server = server,
Channel = channel,
User = user,
RolesBefore = user.Roles,
RolesAfter = new List<Role> { mutedRole },
ExpiresOn = expiresOn,
PunishmentType = PunishmentType.Mute,
Actioned = false
};
_botServices.Defence.PunishUser(punishment);
await _client.EditUser(user, null, null, punishment.RolesAfter);
}
catch (Exception ex)
{
_botServices.Logging.LogError(string.Format("Failed to add '{0} to the muted role'", user.Name), ex);
throw;
}
}
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:31,代码来源:DefenceModule.cs
示例2: CanRun
public bool CanRun(Command command, User user, Channel channel, out string error)
{
error = null;
if (channel.IsPrivate)
return DefaultPermissionLevel <= DefaultPermChecker.GetPermissionLevel(user, channel);
DynPermFullData data = DynPerms.GetPerms(channel.Server.Id);
// apply default perms.
bool retval = DefaultPermissionLevel <= DefaultPermChecker.GetPermissionLevel(user, channel);
// if we do not have dynamic perms in place for the user's server, return the default perms.
if (data == null || (!data.Perms.RolePerms.Any() && !data.Perms.UserPerms.Any()))
return retval;
/*
Firsly do role checks.
Lower entries override higher entries.
To do that we have to iterate over the dict instead of using roles the user has as keys.
*/
foreach (var pair in data.Perms.RolePerms)
{
if (user.HasRole(pair.Key))
retval = EvaluatePerms(pair.Value, command, retval, channel, ref error);
}
// users override roles, do them next.
DynamicPermissionBlock permBlock;
if (data.Perms.UserPerms.TryGetValue(user.Id, out permBlock))
retval = EvaluatePerms(permBlock, command, retval, channel, ref error);
return retval;
}
开发者ID:SSStormy,项目名称:Stormbot,代码行数:35,代码来源:DynamicPermissionChecker.cs
示例3: Invite
internal Invite(DiscordClient client, string code, string xkcdPass, string serverId, string inviterId, string channelId)
: base(client, code)
{
XkcdCode = xkcdPass;
_server = new Reference<Server>(serverId, x =>
{
var server = _client.Servers[x];
if (server == null)
{
server = _generatedServer = new Server(client, x);
server.Cache();
}
return server;
});
_inviter = new Reference<User>(serverId, x =>
{
var inviter = _client.Users[x, _server.Id];
if (inviter == null)
{
inviter = _generatedInviter = new User(client, x, _server.Id);
inviter.Cache();
}
return inviter;
});
_channel = new Reference<Channel>(serverId, x =>
{
var channel = _client.Channels[x];
if (channel == null)
{
channel = _generatedChannel = new Channel(client, x, _server.Id, null);
channel.Cache();
}
return channel;
});
}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:35,代码来源:Invite.cs
示例4: CanRun
public bool CanRun(Command command, User user, Channel channel, out string error) {
error = null;
if (channel.IsPrivate)
return true;
try {
//is it a permission command?
// if it is, check if the user has the correct role
// if yes return true, if no return false
if (command.Category == "Permissions")
if (user.Server.IsOwner || user.HasRole(PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server))))
return true;
else
throw new Exception($"You don't have the necessary role (**{PermissionsHandler._permissionsDict[user.Server].PermissionsControllerRole}**) to change permissions.");
var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel);
string msg;
switch (permissionType) {
case PermissionsHandler.PermissionBanType.None:
return true;
case PermissionsHandler.PermissionBanType.ServerBanCommand:
msg = $"**{command.Text}** command has been banned from use on this **server**.";
break;
case PermissionsHandler.PermissionBanType.ServerBanModule:
msg = $"**{command.Category}** module has been banned from use on this **server**.";
break;
case PermissionsHandler.PermissionBanType.ChannelBanCommand:
msg = $"**{command.Text}** command has been banned from use on this **channel**.";
break;
case PermissionsHandler.PermissionBanType.ChannelBanModule:
msg = $"**{command.Category}** module has been banned from use on this **channel**.";
break;
case PermissionsHandler.PermissionBanType.RoleBanCommand:
msg = $"You do not have a **role** which permits you the usage of **{command.Text}** command.";
break;
case PermissionsHandler.PermissionBanType.RoleBanModule:
msg = $"You do not have a **role** which permits you the usage of **{command.Category}** module.";
break;
case PermissionsHandler.PermissionBanType.UserBanCommand:
msg = $"{user.Mention}, You have been banned from using **{command.Text}** command.";
break;
case PermissionsHandler.PermissionBanType.UserBanModule:
msg = $"{user.Mention}, You have been banned from using **{command.Category}** module.";
break;
default:
return true;
}
if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
Task.Run(() => channel.SendMessage(msg));
return false;
} catch (Exception ex) {
if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
Task.Run(() => channel.SendMessage(ex.Message));
return false;
}
}
开发者ID:TheFerty7,项目名称:NadekoBot,代码行数:59,代码来源:PermissionChecker.cs
示例5: GetMusic
internal static bool GetMusic(User user)
{
SQLiteDataReader reader = SQL.ExecuteReader("select channel from flags where music = 1");
List<long> streams = new List<long>();
while (reader.Read())
streams.Add(Convert.ToInt64(reader["channel"].ToString()));
return user.VoiceChannel != null && streams.Contains(user.VoiceChannel.Id);
}
开发者ID:Lirusaito,项目名称:Nekobot,代码行数:8,代码来源:Flags.cs
示例6: SetChannelPermissions
public Task SetChannelPermissions(Channel channel, User user, ChannelPermissions allow = null, ChannelPermissions deny = null)
{
if (channel == null) throw new ArgumentNullException(nameof(channel));
if (user == null) throw new ArgumentNullException(nameof(user));
CheckReady();
return SetChannelPermissions(channel, user?.Id, PermissionTarget.User, allow, deny);
}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:8,代码来源:DiscordClient.Permissions.cs
示例7: RemoveChannelPermissions
public Task RemoveChannelPermissions(Channel channel, User user)
{
if (channel == null) throw new ArgumentNullException(nameof(channel));
if (user == null) throw new ArgumentNullException(nameof(user));
CheckReady();
return RemoveChannelPermissions(channel, user?.Id, PermissionTarget.User);
}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:8,代码来源:DiscordClient.Permissions.cs
示例8: GetWarningsCount
public int GetWarningsCount(User user)
{
if (_warnings.ContainsKey(user))
{
return _warnings[user];
}
return 0;
}
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:8,代码来源:DefenceService.cs
示例9: CanRun
public bool CanRun(Command command, User user, Channel channel, out string error)
{
error = string.Empty;
if (user.ServerPermissions.ManageRoles)
return true;
error = "You do not have a permission to manage roles.";
return false;
}
开发者ID:Ryonez,项目名称:Lucy,代码行数:8,代码来源:SimpleCheckers.cs
示例10: Ban
/// <summary> Bans a user from the provided server. </summary>
public Task Ban(User user)
{
if (user == null) throw new ArgumentNullException(nameof(user));
if (user.Server == null) throw new ArgumentException("Unable to ban a user in a private chat.");
CheckReady();
return _api.BanUser(user.Server.Id, user.Id);
}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:9,代码来源:DiscordClient.Bans.cs
示例11: AddWarning
public void AddWarning(Channel channel, User user)
{
if (!_warnings.ContainsKey(user))
{
_warnings.Add(user, 0);
}
_warnings[user]++;
NotifyUserWarned(new UserWarnedEventArgs { Channel = channel, User = user, WarningCount = _warnings[user] });
}
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:10,代码来源:DefenceService.cs
示例12: HasNeko
static bool HasNeko(ref string msg, User user)
{
string neko = user.Name;
string nekonick = user.Nickname;
if (HasNekoEmojiOrNot(ref msg, neko)) // Have we been mentioned by our actual name?
{
HasNekoNick(ref msg, nekonick); // Strip nick, too, just in case.
return true;
}
return HasNekoNick(ref msg, nekonick); // Have we been mentioned by our nick?
}
开发者ID:Kusoneko,项目名称:Nekobot,代码行数:11,代码来源:Chatbot.cs
示例13: CanRun
public bool CanRun(Command command, User user, Channel channel, out string error)
{
if (user.IsPrivate)
{
error = "This command can't be run in n a private chat.";
return false;
}
else
{
error = null;
return true;
}
}
开发者ID:Lirusaito,项目名称:Nekobot,代码行数:13,代码来源:PublicChecker.cs
示例14: CanRun
public bool CanRun(Command command, User user, Channel channel, out string error)
{
if (user.Server != null)
{
error = "This command may only be run in a private chat.";
return false;
}
else
{
error = null;
return true;
}
}
开发者ID:Kusoneko,项目名称:Nekobot,代码行数:13,代码来源:PrivateChecker.cs
示例15: AddEvent
public void AddEvent(Server server, Channel channel, User user, EventType eventType)
{
var eventToSave = new Event
{
Id = Guid.NewGuid(),
User = user,
Server = server,
Channel = channel,
EventType = eventType,
OccuredOn = DateTime.Now
};
_eventRepository.Insert(eventToSave);
}
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:14,代码来源:EventService.cs
示例16: MainAsync
public static async Task MainAsync(Server server, Channel channel, User user, IEnumerable<string> args)
{
bool isError = false;
string errorMessage = "";
try
{
Color c = null;
Role r = null;
string colorName = null;
if (args.FirstOrDefault() != null)
colorName = args.FirstOrDefault().ToLower();
c = GetRoleColor(colorName);
if (colorName != null && c != null)
{
if ((r = GetRole(Capitalize(args.First().ToLower()), server.Roles)) != null)
{
await CheckForRolesAsync(user, server.Roles);
await user.AddRoles(r);
}
else
{
await CheckForRolesAsync(user, server.Roles);
string roleName = string.Format("{0}{1}", rolePrefix, Capitalize(colorName));
await user.AddRoles(await server.CreateRole(roleName, color: c));
}
}
else
{
await channel.SendMessage(user.Mention + " Wrong colour input, check help for working colours.");
}
}
catch (Exception ex)
{
isError = true;
errorMessage = ex.Message.ToString();
}
if (isError)
await channel.SendMessage(user.Mention + " " + errorMessage);
await DeleteUnusedRolesAsync(server.Roles);
}
开发者ID:XanderBras,项目名称:ColourBot,代码行数:47,代码来源:ColourCommand.cs
示例17: HelpAsync
public static async Task HelpAsync(Server server, Channel channel, User user, IEnumerable<string> args)
{
bool isError = false;
string errorMessage = "";
try
{
Channel ch = await user.CreatePMChannel();
await ch.SendMessage(WriteHelpMessage());
}
catch (Exception ex)
{
isError = true;
errorMessage = ex.Message.ToString();
}
if (isError)
await channel.SendMessage(user.Mention + " " + errorMessage);
}
开发者ID:XanderBras,项目名称:ColourBot,代码行数:19,代码来源:ColourCommand.cs
示例18: CanRun
public bool CanRun(User user, Channel channel, out string error)
{
error = null;
if (_commands.Count > 0)
{
foreach (var cmd in _commands)
{
if (cmd.CanRun(user, channel, out error))
return true;
}
}
if (_items.Count > 0)
{
foreach (var item in _items)
{
if (item.Value.CanRun(user, channel, out error))
return true;
}
}
return false;
}
开发者ID:Kusoneko,项目名称:Nekobot,代码行数:21,代码来源:CommandMap.cs
示例19: AdjustKarma
public Task<Karma> AdjustKarma(int amount, Channel channel, User toUser, User fromUser = null)
{
var tcs = new TaskCompletionSource<Karma>();
try
{
if (!_karmaRepository.Exists(toUser.Id))
{
_karmaRepository.Insert(new Karma { Id = toUser.Id, User = toUser, Amount = 0, LastUpdated = DateTime.Now });
}
var karma = _karmaRepository.GetById(toUser.Id);
karma.Amount += amount;
karma.LastUpdated = DateTime.Now;
_karmaRepository.Update(karma);
NotifyKarmaChanged(new KarmaChangedEventArgs { Channel = channel, FromUser = fromUser, ToUser = toUser, Amount = amount });
var nextRank = GetNextRank(karma.Amount);
if (karma.Amount == nextRank.RequiredKarma)
{
NotifyRankChanged(new RankChangedEventArgs { Channel = channel, User = toUser, NewRank = nextRank });
}
tcs.TrySetResult(karma);
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
if (tcs.Task.Exception != null)
{
throw tcs.Task.Exception;
}
return tcs.Task;
}
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:38,代码来源:KarmaService.cs
示例20: CheckUserSpamming
public Task<bool> CheckUserSpamming(Channel channel, User user, DateTime timeStamp)
{
var tcs = new TaskCompletionSource<bool>();
try
{
if (!_messages.ContainsKey(user))
{
_messages.Add(user, new List<DateTime> { timeStamp });
tcs.TrySetResult(false);
}
_messages[user].Add(timeStamp);
var messagesWithinThreshold = _messages[user].Where(m => m > DateTime.Now.AddSeconds(-10));
if (messagesWithinThreshold.Count() > 3)
{
NotifyUserSpamming(new UserSpammingEventArgs { Channel = channel, User = user});
tcs.TrySetResult(true);
}
tcs.TrySetResult(false);
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
if (tcs.Task.Exception != null)
{
throw tcs.Task.Exception;
}
return tcs.Task;
}
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:37,代码来源:DefenceService.cs
注:本文中的Discord.User类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论