本文整理汇总了C#中Discord.Server类的典型用法代码示例。如果您正苦于以下问题:C# Server类的具体用法?C# Server怎么用?C# Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Server类属于Discord命名空间,在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例2: CreateInvite
/// <summary> Creates a new invite to the default channel of the provided server. </summary>
/// <param name="maxAge"> Time (in seconds) until the invite expires. Set to 0 to never expire. </param>
/// <param name="tempMembership"> If true, a user accepting this invite will be kicked from the server after closing their client. </param>
/// <param name="hasXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to 0. </param>
/// <param name="maxUses"> The max amount of times this invite may be used. Set to 0 to have unlimited uses. </param>
public Task<Invite> CreateInvite(Server server, int maxAge = 1800, int maxUses = 0, bool tempMembership = false, bool hasXkcd = false)
{
if (server == null) throw new ArgumentNullException(nameof(server));
CheckReady();
return CreateInvite(server.DefaultChannel, maxAge, maxUses, tempMembership, hasXkcd);
}
示例3: ConvertToNames
internal static string ConvertToNames(DiscordClient client, Server server, string text)
{
text = _userRegex.Replace(text, new MatchEvaluator(e =>
{
string id = e.Value.Substring(2, e.Value.Length - 3);
var user = client.Users[id, server?.Id];
if (user != null)
return '@' + user.Name;
else //User not found
return '@' + e.Value;
}));
if (server != null)
{
text = _channelRegex.Replace(text, new MatchEvaluator(e =>
{
string id = e.Value.Substring(2, e.Value.Length - 3);
var channel = client.Channels[id];
if (channel != null && channel.Server.Id == server.Id)
return '#' + channel.Name;
else //Channel not found
return '#' + e.Value;
}));
}
return text;
}
示例4: 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;
});
}
示例5: ValidateUser
internal static User ValidateUser(Server server, string userName) {
if (string.IsNullOrWhiteSpace(userName))
throw new ArgumentNullException(nameof(userName));
var user = server.FindUsers(userName).FirstOrDefault();
if (user == null)
throw new NullReferenceException("That user does not exist.");
return user;
}
示例6: Role
internal Role(ulong id, Server server)
{
Id = id;
Server = server;
Permissions = new ServerPermissions(0);
Color = new Color(0);
}
示例7: GetChannelPermissionsById
internal static Permissions GetChannelPermissionsById(Server server, ulong id) {
if (!_permissionsDict.ContainsKey(server))
return null;
Permissions toReturn;
_permissionsDict[server].ChannelPermissions.TryGetValue(id, out toReturn);
return toReturn;
}
示例8: ValidateChannel
internal static Channel ValidateChannel(Server server, string channelName) {
if (string.IsNullOrWhiteSpace(channelName))
throw new ArgumentNullException(nameof(channelName));
var channel = server.FindChannels(channelName, ChannelType.Text).FirstOrDefault();
if (channel == null)
throw new NullReferenceException("That channel does not exist.");
return channel;
}
示例9: Unban
/// <summary> Unbans a user from the provided server. </summary>
public async Task Unban(Server server, string userId)
{
if (server == null) throw new ArgumentNullException(nameof(server));
if (userId == null) throw new ArgumentNullException(nameof(userId));
CheckReady();
try { await _api.UnbanUser(server.Id, userId).ConfigureAwait(false); }
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}
示例10: GetChannelPermissionsById
internal static Permissions GetChannelPermissionsById(Server server, ulong id)
{
ServerPermissions serverPerms;
if (!PermissionsDict.TryGetValue(server.Id, out serverPerms))
return null;
Permissions toReturn;
serverPerms.ChannelPermissions.TryGetValue(id, out toReturn);
return toReturn;
}
示例11: ValidateRole
internal static Role ValidateRole(Server server, string roleName) {
if (string.IsNullOrWhiteSpace(roleName))
throw new ArgumentNullException(nameof(roleName));
if (roleName.Trim() == "everyone")
roleName = "@everyone";
var role = server.FindRoles(roleName).FirstOrDefault();
if (role == null)
throw new NullReferenceException("That role does not exist.");
return role;
}
示例12: ChangeColor
private async Task ChangeColor(Server s)
{
for(int i = 0; i < 100; i++)
{
Role role = s.GetUser(Disco.Bot.Client.CurrentUser.Id).Roles.FirstOrDefault();
currentColor++;
await role.Edit(null, null, _colors[currentColor % 15].Color);
Thread.Sleep(100);
}
}
示例13: GetStatistics
public Statistics GetStatistics(Server server)
{
return new Statistics
{
ServerName = server.Name,
Owner = server.Owner,
CreatedOn = server.Owner.JoinedAt,
TotalMembers = server.Members.Count(),
Karma = GetKarma(),
Messages = GetMessages(server),
Mentions = GetMentions(server)
};
}
示例14: GetInvites
/// <summary> Gets all active (non-expired) invites to a provided server. </summary>
public async Task<Invite[]> GetInvites(Server server)
{
if (server == null) throw new ArgumentNullException(nameof(server));
CheckReady();
var response = await _api.GetInvites(server.Id).ConfigureAwait(false);
return response.Select(x =>
{
var invite = new Invite(this, x.Code, x.XkcdPass, x.Guild.Id, x.Inviter?.Id, x.Channel?.Id);
invite.Cache(); //Builds references
invite.Update(x);
return invite;
}).ToArray();
}
示例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);
}