dialect.defs.IRCChannel whose modes are being set.
String of the raw mode command, including the prefixing sign (+ or -).
Appendix to the signed modestring; arguments to the modes that are being set.
The current IRCServer with all its settings.
IRCServer server; IRCChannel channel; channel.setMode("+oo", "zorael!NaN@* kameloso!*@*", server); assert(channel.modes.length == 2); channel.setMode("-o", "kameloso!*@*", server); assert(channel.modes.length == 1); channel.setMode("-o" "*!*@*", server); assert(!channel.modes.length);
1 import std.conv; 2 import std.stdio; 3 4 IRCServer server; 5 // Freenode: CHANMODES=eIbq,k,flj,CFLMPQScgimnprstz 6 with (server) 7 { 8 aModes = "eIbq"; 9 bModes = "k"; 10 cModes = "flj"; 11 dModes = "CFLMPQScgimnprstz"; 12 13 // SpotChat: PREFIX=(Yqaohv)!~&@%+ 14 prefixes = "Yaohv"; 15 prefixchars = 16 [ 17 '!' : 'Y', 18 '&' : 'a', 19 '@' : 'o', 20 '%' : 'h', 21 '+' : 'v', 22 ]; 23 24 extbanPrefix = '$'; 25 exceptsChar = 'e'; 26 invexChar = 'I'; 27 } 28 29 { 30 IRCChannel chan; 31 32 chan.topic = "Huerbla"; 33 34 chan.setMode("+b", "kameloso!~NaN@aasdf.freenode.org", server); 35 //foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 36 //writeln("-------------------------------------"); 37 assert((chan.modes.length == 1), chan.modes.length.to!string); 38 39 chan.setMode("+bbe", "hirrsteff!*@* harblsnarf!ident@* NICK!~IDENT@ADDRESS", server); 40 //foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 41 //writeln("-------------------------------------"); 42 assert((chan.modes.length == 3), chan.modes.length.to!string); 43 44 chan.setMode("-b", "*!*@*", server); 45 //foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 46 //writeln("-------------------------------------"); 47 assert((chan.modes.length == 3), chan.modes.length.to!string); 48 49 chan.setMode("+i", string.init, server); 50 assert(chan.modechars == "i", chan.modechars); 51 52 chan.setMode("+v", "harbl", server); 53 assert(chan.modechars == "i", chan.modechars); 54 55 chan.setMode("-i", string.init, server); 56 assert(!chan.modechars.length, chan.modechars); 57 58 chan.setMode("+l", "200", server); 59 IRCChannel.Mode lMode; 60 lMode.modechar = 'l'; 61 lMode.data = "200"; 62 //foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 63 //writeln("-------------------------------------"); 64 assert((chan.modes[3] == lMode), chan.modes[3].to!string); 65 66 chan.setMode("+l", "100", server); 67 lMode.modechar = 'l'; 68 lMode.data = "100"; 69 //foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 70 //writeln("-------------------------------------"); 71 assert((chan.modes[3] == lMode), chan.modes[3].to!string); 72 } 73 74 { 75 IRCChannel chan; 76 77 chan.setMode("+CLPcnprtf", "##linux-overflow", server); 78 //foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 79 //writeln("-------------------------------------"); 80 assert(chan.modes[0].data == "##linux-overflow"); 81 assert(chan.modes.length == 1); 82 assert(chan.modechars.length == 8); 83 84 chan.setMode("+bee", "mynick!myident@myaddress abc!def@ghi jkl!*@*", server); 85 //foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 86 //writeln("-------------------------------------"); 87 assert(chan.modes.length == 2); 88 assert(chan.modes[1].exceptions.length == 2); 89 } 90 91 { 92 IRCChannel chan; 93 94 chan.setMode("+ns", string.init, server); 95 foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 96 assert(chan.modes.length == 0); 97 assert(chan.modechars == "sn", chan.modechars); 98 99 chan.setMode("-sn", string.init, server); 100 foreach (i, mode; chan.modes) writefln("%2d: %s", i, mode); 101 assert(chan.modes.length == 0); 102 assert(chan.modechars.length == 0); 103 } 104 105 { 106 IRCChannel chan; 107 chan.setMode("+oo", "kameloso zorael", server); 108 assert(chan.mods['o'].length == 2); 109 chan.setMode("-o", "kameloso", server); 110 assert(chan.mods['o'].length == 1); 111 chan.setMode("-o", "zorael", server); 112 assert(!chan.mods['o'].length); 113 } 114 115 { 116 IRCChannel chan; 117 server.extbanPrefix = '$'; 118 119 chan.setMode("+b", "$a:hirrsteff", server); 120 assert(chan.modes.length); 121 with (chan.modes[0]) 122 { 123 assert((modechar == 'b'), modechar.text); 124 assert((user.account == "hirrsteff"), user.account); 125 } 126 127 chan.setMode("+q", "$~a:blarf", server); 128 assert((chan.modes.length == 2), chan.modes.length.text); 129 with (chan.modes[1]) 130 { 131 assert((modechar == 'q'), modechar.text); 132 assert((user.account == "blarf"), user.account); 133 assert(negated); 134 IRCUser blarf; 135 blarf.nickname = "blarf"; 136 blarf.account = "blarf"; 137 assert(blarf.matchesByMask(user)); 138 } 139 } 140 141 { 142 IRCChannel chan; 143 144 chan.setMode("+t", string.init, server); 145 assert(!chan.modes.length, chan.modes.length.text); 146 assert((chan.modechars == "t"), chan.modechars); 147 148 chan.setMode("-t+nlk", "42 chankey", server); 149 assert((chan.modes.length == 2), chan.modes.length.text); 150 with (chan.modes[0]) 151 { 152 assert((modechar == 'k'), modechar.text); 153 assert((data == "chankey"), data); 154 } 155 with (chan.modes[1]) 156 { 157 assert((modechar == 'l'), modechar.text); 158 assert((data == "42"), data); 159 } 160 161 assert((chan.modechars == "n"), chan.modechars); 162 163 chan.setMode("-kl", string.init, server); 164 assert(!chan.modes.length, chan.modes.length.text); 165 }
Sets a new or removes a IRCChannel.Mode.
IRCChannel.Modes that are merely a character in modechars are simply removed if the *sign* of the mode change is negative, whereas a more elaborate IRCChannel.Mode in the modes array are only replaced or removed if they match a comparison test.
Several modes can be specified at once, including modes that take a data argument, assuming they are in the proper order (where the data-taking modes are at the end of the string).
Care has to be taken not to have trailing spaces in the arguments.