This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TaskCompletionExtensions | |
{ | |
public static Task<T> FirstCompletedTask<T>(this IEnumerable<Task<T>> source) | |
{ | |
foreach (var completedTask in tasks.InCompletionOrder()) | |
{ | |
if (completedTask.Status == TaskStatus.RanToCompletion) | |
{ | |
return completedTask; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private readonly PrefixService _prefixService = new PrefixService(); | |
//..... | |
private IServiceProvider ConfigureServices() | |
{ | |
var map = new ServiceCollection() | |
.AddSingleton(_prefixService) | |
//.... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
internal sealed class Del | |
{ | |
internal void Run() => _act(); | |
private Action _act; | |
internal Action Act { set => _act = value; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using System.Threading.Tasks; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var method = typeof(Program).GetMethod(nameof(Foo), BindingFlags.Static | BindingFlags.NonPublic); | |
var task = method.Invoke(new object(), Array.Empty<object>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | |
public class RequireAdminOrOwnerAttribute : PreconditionAttribute | |
{ | |
private readonly RequireOwnerAttribute _owner = new RequireOwnerAttribute(); | |
private readonly RequireUserPermissionAttribute _admins = new RequireUserPermissionAttribute(GuildPermission.Administrator); | |
public override async Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) | |
{ | |
var isAdmin = await _admins.CheckPermissions(context, command, services); | |
var isOwner = await _owner.CheckPermissions(context, command, services); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
using Discord.Commands; | |
public class AudioModule : ModuleBase<ICommandContext> | |
{ | |
// Scroll down further for the AudioService. | |
// Like, way down | |
private readonly AudioService _service; | |
// Remember to add an instance of the AudioService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using System.Threading.Tasks; | |
using Discord; | |
using Discord.Commands; | |
using Discord.WebSocket; | |
class Program | |
{ | |
private readonly DiscordSocketClient client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; // 1) Add this namespace | |
using System.Threading.Tasks; | |
using Discord.Commands; | |
public class TimerService | |
{ | |
private readonly Timer _timer; // 2) Add a field like this | |
// This example only concerns a single timer. | |
// If you would like to have multiple independant timers, |