本文整理汇总了C#中Discord.User.Update方法的典型用法代码示例。如果您正苦于以下问题:C# User.Update方法的具体用法?C# User.Update怎么用?C# User.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.User
的用法示例。
在下文中一共展示了User.Update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBans
public async Task<IEnumerable<User>> GetBans()
{
var response = await Client.ClientAPI.Send(new GetBansRequest(Id)).ConfigureAwait(false);
return response.Select(x =>
{
var user = new User(Client, x.Id, this);
user.Update(x);
return user;
});
}
示例2: OnReceivedEvent
private void OnReceivedEvent(WebSocketEventEventArgs e)
{
try
{
switch (e.Type)
{
//Global
case "READY":
{
Stopwatch stopwatch = null;
if (Config.LogLevel >= LogSeverity.Verbose)
stopwatch = Stopwatch.StartNew();
var data = e.Payload.ToObject<ReadyEvent>(_serializer);
GatewaySocket.StartHeartbeat(data.HeartbeatInterval);
GatewaySocket.SessionId = data.SessionId;
SessionId = data.SessionId;
PrivateUser = new User(this, data.User.Id, null);
PrivateUser.Update(data.User);
CurrentUser = new Profile(this, data.User.Id);
CurrentUser.Update(data.User);
foreach (var model in data.Guilds)
{
if (model.Unavailable != true)
{
var server = AddServer(model.Id);
server.Update(model);
}
}
foreach (var model in data.PrivateChannels)
{
var channel = AddPrivateChannel(model.Id, model.Recipient.Id);
channel.Update(model);
}
if (Config.LogLevel >= LogSeverity.Verbose)
{
stopwatch.Stop();
double seconds = Math.Round(stopwatch.ElapsedTicks / (double)TimeSpan.TicksPerSecond, 2);
Logger.Verbose($"READY took {seconds} sec");
}
}
break;
case "RESUMED":
{
var data = e.Payload.ToObject<ResumedEvent>(_serializer);
GatewaySocket.StartHeartbeat(data.HeartbeatInterval);
}
break;
//Servers
case "GUILD_CREATE":
{
var data = e.Payload.ToObject<GuildCreateEvent>(_serializer);
if (data.Unavailable != true)
{
var server = AddServer(data.Id);
server.Update(data);
if (Config.LogEvents)
{
if (data.Unavailable != false)
Logger.Info($"Server Created: {server.Name}");
else
Logger.Info($"Server Available: {server.Name}");
}
if (data.Unavailable != false)
OnJoinedServer(server);
OnServerAvailable(server);
}
}
break;
case "GUILD_UPDATE":
{
var data = e.Payload.ToObject<GuildUpdateEvent>(_serializer);
var server = GetServer(data.Id);
if (server != null)
{
server.Update(data);
if (Config.LogEvents)
Logger.Info($"Server Updated: {server.Name}");
OnServerUpdated(server);
}
else
Logger.Warning("GUILD_UPDATE referenced an unknown guild.");
}
break;
case "GUILD_DELETE":
{
var data = e.Payload.ToObject<GuildDeleteEvent>(_serializer);
Server server = RemoveServer(data.Id);
if (server != null)
{
if (Config.LogEvents)
{
if (data.Unavailable != true)
Logger.Info($"Server Destroyed: {server.Name}");
else
Logger.Info($"Server Unavailable: {server.Name}");
}
//.........这里部分代码省略.........
示例3: OnReceivedEvent
internal override async Task OnReceivedEvent(WebSocketEventEventArgs e)
{
try
{
await base.OnReceivedEvent(e);
switch (e.Type)
{
//Global
case "READY": //Resync
{
var data = e.Payload.ToObject<ReadyEvent>(_serializer);
_currentUser = _users.GetOrAdd(data.User.Id);
_currentUser.Update(data.User);
foreach (var model in data.Guilds)
{
if (!model.Unavailable)
{
var server = _servers.GetOrAdd(model.Id);
server.Update(model);
}
}
foreach (var model in data.PrivateChannels)
{
var user = _users.GetOrAdd(model.Recipient.Id);
user.Update(model.Recipient);
var channel = _channels.GetOrAdd(model.Id, null, user.Id);
channel.Update(model);
}
}
break;
//Servers
case "GUILD_CREATE":
{
var data = e.Payload.ToObject<GuildCreateEvent>(_serializer);
if (!data.Unavailable)
{
var server = _servers.GetOrAdd(data.Id);
server.Update(data);
if (data.Unavailable == false)
RaiseServerAvailable(server);
else
RaiseServerCreated(server);
}
}
break;
case "GUILD_UPDATE":
{
var data = e.Payload.ToObject<GuildUpdateEvent>(_serializer);
var server = _servers[data.Id];
if (server != null)
{
server.Update(data);
RaiseServerUpdated(server);
}
}
break;
case "GUILD_DELETE":
{
var data = e.Payload.ToObject<GuildDeleteEvent>(_serializer);
var server = _servers.TryRemove(data.Id);
if (server != null)
{
if (data.Unavailable == true)
RaiseServerAvailable(server);
else
RaiseServerDestroyed(server);
}
}
break;
//Channels
case "CHANNEL_CREATE":
{
var data = e.Payload.ToObject<ChannelCreateEvent>(_serializer);
Channel channel;
if (data.IsPrivate)
{
var user = _users.GetOrAdd(data.Recipient.Id);
user.Update(data.Recipient);
channel = _channels.GetOrAdd(data.Id, null, user.Id);
}
else
channel = _channels.GetOrAdd(data.Id, data.GuildId, null);
channel.Update(data);
RaiseChannelCreated(channel);
}
break;
case "CHANNEL_UPDATE":
{
var data = e.Payload.ToObject<ChannelUpdateEvent>(_serializer);
var channel = _channels[data.Id];
if (channel != null)
{
channel.Update(data);
RaiseChannelUpdated(channel);
}
}
break;
//.........这里部分代码省略.........
示例4: CreatePMChannel
private async Task<Channel> CreatePMChannel(User user, string userId)
{
CheckReady();
if (userId == null) throw new ArgumentNullException(nameof(userId));
Channel channel = null;
if (user != null)
channel = user.PrivateChannel;
if (channel == null)
{
var response = await _api.CreatePMChannel(CurrentUserId, userId).ConfigureAwait(false);
user = _users.GetOrAdd(response.Recipient?.Id);
user.Update(response.Recipient);
channel = _channels.GetOrAdd(response.Id, response.GuildId, response.Recipient?.Id);
channel.Update(response);
}
return channel;
}