Skip to content

Instantly share code, notes, and snippets.

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;
}
class Program
{
private readonly PrefixService _prefixService = new PrefixService();
//.....
private IServiceProvider ConfigureServices()
{
var map = new ServiceCollection()
.AddSingleton(_prefixService)
//....
using System;
using System.Runtime.CompilerServices;
internal sealed class Del
{
internal void Run() => _act();
private Action _act;
internal Action Act { set => _act = value; }
}
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>());
@Joe4evr
Joe4evr / CombinedPreconditionExample.cs
Created May 25, 2017 09:30
Example of how to make a logical OR of multiple preconditions
[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);
@Joe4evr
Joe4evr / AudioModule.cs
Last active October 18, 2023 15:32
D.Net 1.0 audio example
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
using System;
using System.Reflection;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
class Program
{
private readonly DiscordSocketClient client;
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,