File: dau.pl

package info (click to toggle)
irssi-scripts 20070925
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,708 kB
  • ctags: 2,415
  • sloc: perl: 54,737; makefile: 43; sh: 20
file content (4416 lines) | stat: -rw-r--r-- 131,283 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
################################################################################
# $Id: dau.pl 12 2005-01-28 10:09:47Z ch $
################################################################################
#
# dau.pl - write like an idiot
#
################################################################################
# Author
################################################################################
#
# Clemens Heidinger
#
# email: spoooky@dau.pl
#
# IRC:   IRCNet/EFnet:
#        spoooky*!*spoooky@*.geekmind.org
#
################################################################################
# Changelog
################################################################################
#
# dau.pl has a builtin changelog (--changelog switch)
#
################################################################################
# Credits
################################################################################
#
# - Robert 'rob' Hennig: For the original dau.pl-shell-script. Out of this
#   script, merged with some other small Perl- and shellscripts and aliases
#   arised the first version of dau.pl for irssi.
#
# - The various people reporting bugs and making suggestions. Too many to
#   remember and to mention them all here.
#
################################################################################
# Documentation
################################################################################
#
# dau.pl has a builtin help (--help switch)
#
################################################################################
# License
################################################################################
#
# Licensed under the BSD license
#
################################################################################
# Website
################################################################################
#
# http://dau.pl/
#
# For additional information, downloads, the dauomat and the dauproxy
#
################################################################################

use 5.6.0;
use File::Basename;
use File::Path;
use IPC::Open3;
use Irssi 20021107.0841;
use Irssi::TextUI;
use locale;
use re 'eval';
use strict;
use vars qw($VERSION %IRSSI);

$VERSION = '1.9.0';
#$VERSION = '1.9.0 SVN ($LastChangedRevision: 12 $)';
%IRSSI = (
          authors     => 'Clemens Heidinger',
          changed     => '$LastChangedDate: 2005-01-28 11:09:47 +0100 (Fri, 28 Jan 2005) $',
          commands    => 'dau',
          contact     => 'spoooky@dau.pl',
          description => 'write like an idiot',
          license     => 'BSD',
          modules     => 'File::Basename File::Path IPC::Open3',
          name        => 'DAU',
          sbitems     => 'daumode',
          url         => 'http://dau.pl/',
         );

################################################################################
# Register commands
################################################################################

Irssi::command_bind('dau', \&command_dau);

################################################################################
# Register settings
################################################################################

# boolean
Irssi::settings_add_bool('misc', 'dau_babble_verbose', 1);
Irssi::settings_add_bool('misc', 'dau_cowsay_print_cow', 0);
Irssi::settings_add_bool('misc', 'dau_figlet_print_font', 0);
Irssi::settings_add_bool('misc', 'dau_statusbar_daumode_hide_when_off', 0);
Irssi::settings_add_bool('misc', 'dau_tab_completion', 1);

# Integer
Irssi::settings_add_int('misc', 'dau_babble_verbose_minimum_lines', 2);
Irssi::settings_add_int('misc', 'dau_remote_babble_interval', 3600);
Irssi::settings_add_int('misc', 'dau_remote_babble_interval_accuracy', 90);

# String
Irssi::settings_add_str('misc', 'dau_babble_standard_options', '--nothing');
Irssi::settings_add_str('misc', 'dau_cowsay_cowlist', '');
Irssi::settings_add_str('misc', 'dau_cowsay_cowpath', &def_dau_cowsay_cowpath);
Irssi::settings_add_str('misc', 'dau_cowsay_cowpolicy', 'allow');
Irssi::settings_add_str('misc', 'dau_cowsay_cowsay_path', &def_dau_cowsay_cowsay_path);
Irssi::settings_add_str('misc', 'dau_cowsay_cowthink_path', &def_dau_cowsay_cowthink_path);
Irssi::settings_add_str('misc', 'dau_delimiter_string', ' ');
Irssi::settings_add_str('misc', 'dau_figlet_fontlist', 'mnemonic,term,ivrit');
Irssi::settings_add_str('misc', 'dau_figlet_fontpath', &def_dau_figlet_fontpath);
Irssi::settings_add_str('misc', 'dau_figlet_fontpolicy', 'allow');
Irssi::settings_add_str('misc', 'dau_figlet_path', &def_dau_figlet_path);
Irssi::settings_add_str('misc', 'dau_files_babble_messages', 'babble_messages');
Irssi::settings_add_str('misc', 'dau_files_moron_own_substitutions', 'moron_own_substitutions.pl');
Irssi::settings_add_str('misc', 'dau_files_root_directory', "$ENV{HOME}/.dau");
Irssi::settings_add_str('misc', 'dau_moron_eol_style', 'new');
Irssi::settings_add_str('misc', 'dau_moron_substitutions_permissions', '000');
Irssi::settings_add_str('misc', 'dau_random_options',
                                                      '--boxes --uppercase,' .
                                                      '--color --uppercase,' .
                                                      '--delimiter,' .
                                                      '--dots --moron,' .
                                                      '--leet,' .
                                                      '--mix,' .
                                                      '--mixedcase --bracket,' .
                                                      '--moron --stutter --uppercase,' .
                                                      '--moron -omega yes,' .
                                                      '--moron,' .
                                                      '--uppercase --underline,' .
                                                      '--words --mixedcase'
);
Irssi::settings_add_str('misc', 'dau_remote_babble_channellist', '');
Irssi::settings_add_str('misc', 'dau_remote_babble_channelpolicy', 'deny');
Irssi::settings_add_str('misc', 'dau_remote_channellist', '');
Irssi::settings_add_str('misc', 'dau_remote_channelpolicy', 'deny');
Irssi::settings_add_str('misc', 'dau_remote_deop_reply', 'you are on my shitlist now @ $nick');
Irssi::settings_add_str('misc', 'dau_remote_devoice_reply', 'you are on my shitlist now @ $nick');
Irssi::settings_add_str('misc', 'dau_remote_op_reply', 'thx 4 op @ $nick');
Irssi::settings_add_str('misc', 'dau_remote_permissions', '000000');
Irssi::settings_add_str('misc', 'dau_remote_question_reply', 'alles klar @ $nick');
Irssi::settings_add_str('misc', 'dau_remote_voice_reply', 'thx 4 voice @ $nick');
Irssi::settings_add_str('misc', 'dau_standard_messages', 'hi @ all');
Irssi::settings_add_str('misc', 'dau_standard_options', '--random');
Irssi::settings_add_str('misc', 'dau_words_range', '1-4');

################################################################################
# Register signals
# (Note that most signals are set dynamical in the subroutine signal_handling)
################################################################################

Irssi::signal_add_last('setup changed', \&signal_setup_changed);
Irssi::signal_add_last('window changed' => sub { Irssi::statusbar_items_redraw('daumode') });
Irssi::signal_add_last('window item changed' => sub { Irssi::statusbar_items_redraw('daumode') });

################################################################################
# Register statusbar items
################################################################################

Irssi::statusbar_item_register('daumode', '', 'statusbar_daumode');

################################################################################
# Global variables
################################################################################

# Containing irssi's 'cmdchars'

our $k = Irssi::parse_special('$k');

# Miscellaneous things

our %misc = (
    random_last => '',
    signals     => {
                    'complete word'     => 0,
                    'event privmsg'     => 0,
                    'nick mode changed' => 0,
                    'send text'         => 0,
                    'signals idaumode'  => 0,
                   },
);

# All the options

our %option;

# All switches that may be given at commandline

our %switches = (

    # These switches may be combined

    combo  => {
                boxes     => { 'sub' => \&switch_boxes },
                bracket   => { 'sub' => \&switch_bracket },
                chars     => { 'sub' => \&switch_chars },
                color     => {
                              'sub'   => \&switch_color,
                              'split' => {
                                          chars     => 1,
                                          lines     => 1,
                                          paragraph => 1,
                                          rchars    => 1,
                                          words     => 1,
                                         },
                             },
                command   => {
                              'sub' => \&switch_command,
                               in   => { '*' => 1 },
                               out  => { '*' => 1 },
                               },
                cowsay    => {
                              'sub'       => \&switch_cowsay,
                               arguments  => { '*' => 1 },
                               think      => {
                                              no  => 1,
                                              yes => 1,
                                             },
                             },
                delimiter => {
                              'sub'    => \&switch_delimiter,
                               string  => { '*' => 1 },
                             },
                dots      => { 'sub' => \&switch_dots },
                figlet    => { 'sub' => \&switch_figlet },
                greet     => {
                              'sub'  => \&switch_greet,
                               whom  => {
                                         all   => 1,
                                         rnick => 1,
                                        },
                             },
                me        => { 'sub' => \&switch_me },
                mix       => { 'sub' => \&switch_mix },
                moron     => {
                              'sub'      => \&switch_moron,
                               eol       => {
                                             classic => 1,
                                             'new'   => 1,
                                             nothing => 1,
                                            },
                               omega     => {
                                             no  => 1,
                                             yes => 1,
                                            },
                               perm      => {
                                             '000' => 1,
                                             '001' => 1,
                                             '010' => 1,
                                             '011' => 1,
                                             '100' => 1,
                                             '101' => 1,
                                             '110' => 1,
                                             '111' => 1,
                                            },
                               uppercase => {
                                              no  => 1,
                                              yes => 1,
                                             },
                             },
                leet      => { 'sub' => \&switch_leet },
                mixedcase => { 'sub' => \&switch_mixedcase },
                nothing   => { 'sub' => \&switch_nothing },
                'reverse' => { 'sub' => \&switch_reverse },
                stutter   => { 'sub' => \&switch_stutter },
                underline => { 'sub' => \&switch_underline },
                uppercase => { 'sub' => \&switch_uppercase },
                words     => { 'sub' => \&switch_words },
               },

    # The following switches must not be combined

    nocombo => {
                babble       => { 'sub' => \&switch_babble },
                changelog    => { 'sub' => \&switch_changelog },
                create_files => { 'sub' => \&switch_create_files },
                daumode      => {
                                 'sub'   => \&switch_daumode,
                                  imodes => { '*' => 1 },
                                  omodes => { '*' => 1 },
                                  perm   => {
                                             '00' => 1,
                                             '01' => 1,
                                             '10' => 1,
                                             '11' => 1,
                                            },
                                },
                help         => {
                                 'sub'     => \&switch_help,

                                 # setting changed/added => change/add it here

                                 setting => {
                                             # boolean
                                             dau_babble_verbose                  => 1,
                                             dau_cowsay_print_cow                => 1,
                                             dau_figlet_print_font               => 1,
                                             dau_statusbar_daumode_hide_when_off => 1,
                                             dau_tab_completion                  => 1,

                                             # Integer
                                             dau_babble_verbose_minimum_lines    => 1,
                                             dau_remote_babble_interval          => 1,
                                             dau_remote_babble_interval_accuracy => 1,

                                             # String
                                             dau_babble_standard_options         => 1,
                                             dau_cowsay_cowlist                  => 1,
                                             dau_cowsay_cowpath                  => 1,
                                             dau_cowsay_cowpolicy                => 1,
                                             dau_cowsay_cowsay_path              => 1,
                                             dau_cowsay_cowthink_path            => 1,
                                             dau_delimiter_string                => 1,
                                             dau_figlet_fontlist                 => 1,
                                             dau_figlet_fontpath                 => 1,
                                             dau_figlet_fontpolicy               => 1,
                                             dau_figlet_path                     => 1,
                                             dau_files_babble_messages           => 1,
                                             dau_files_moron_own_substitutions   => 1,
                                             dau_files_root_directory            => 1,
                                             dau_moron_eol_style                 => 1,
                                             dau_moron_substitutions_permissions => 1,
                                             dau_random_options                  => 1,
                                             dau_remote_babble_channellist       => 1,
                                             dau_remote_babble_channelpolicy     => 1,
                                             dau_remote_channellist              => 1,
                                             dau_remote_channelpolicy            => 1,
                                             dau_remote_deop_reply               => 1,
                                             dau_remote_devoice_reply            => 1,
                                             dau_remote_op_reply                 => 1,
                                             dau_remote_permissions              => 1,
                                             dau_remote_question_reply           => 1,
                                             dau_remote_voice_reply              => 1,
                                             dau_standard_messages               => 1,
                                             dau_standard_options                => 1,
                                             dau_words_range                     => 1,
                                            },
                                },
                random => { 'sub' => \&switch_random },
               },
);

################################################################################
# Code run once at start
################################################################################

set_settings();

build_nick_mode_struct();
cowsay_cowlist($option{dau_cowsay_cowpath});
figlet_fontlist($option{dau_figlet_fontpath});
signal_handling();
timer_babble_reset();

print CLIENTCRAP "dau.pl $VERSION loaded. For help type %9${k}dau --help%9";

################################################################################
# Subroutines (commands)
################################################################################

sub command_dau {
	my ($data, $server, $witem) = @_;
	my $output;

	$output = parse_text($data, $witem);

	unless (defined($server) && $server && $server->{connected}) {
		$misc{'print'} = 1;
	}
	unless ((defined($witem) && $witem &&
	       ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY')))
	{
		$misc{'print'} = 1;
	}

	if ($misc{daumode}) {

		if (defined($witem) && $witem &&
		   ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY'))
		{
			my $modes_set = 0;

			# daumode set with parameters (imodes)

			if ($misc{queue}{0}{daumode}{imodes}) {
				$misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} = 1;
				$misc{daumode_ichannels_modes}{$server->{tag}}{$witem->{name}} =
				$misc{queue}{0}{daumode}{imodes};
				$modes_set = 1;
			}

			# daumode set with parameters (omodes)

			if ($misc{queue}{0}{daumode}{omodes}) {
				$misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} = 1;
				$misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} =
				$misc{queue}{0}{daumode}{omodes};
				$modes_set = 1;
			}

			# daumode set without parameters

			if (!$misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} &&
			    !$misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} &&
			    !$modes_set)
			{
				$misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} = 1;
				$misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} = 1;
				$misc{daumode_ichannels_modes}{$server->{tag}}{$witem->{name}} = '';
				$misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} = '';
			}

			# daumode unset

			elsif (($misc{daumode_ichannels}{$server->{tag}}{$witem->{name}}  ||
			        $misc{daumode_ochannels}{$server->{tag}}{$witem->{name}}) &&
			        !$modes_set)
			{
				$misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} = 0;
				$misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} = 0;
				$misc{daumode_ichannels_modes}{$server->{tag}}{$witem->{name}} = '';
				$misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} = '';
			}


			# the perm-option overrides everything

			# perm: 00

			if ($misc{queue}{0}{daumode}{perm} eq '00') {
				$misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} = 0;
				$misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} = 0;
				$misc{daumode_ichannels_modes}{$server->{tag}}{$witem->{name}} = '';
				$misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} = '';
			}

			# perm: 01

			if ($misc{queue}{0}{daumode}{perm} eq '01') {
				$misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} = 0;
				$misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} = 1;
				$misc{daumode_ichannels_modes}{$server->{tag}}{$witem->{name}} = '';
			}

			# perm: 10

			if ($misc{queue}{0}{daumode}{perm} eq '10') {
				$misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} = 1;
				$misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} = 0;
				$misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} = '';
			}

			# perm: 11

			if ($misc{queue}{0}{daumode}{perm} eq '11') {
				$misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} = 1;
				$misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} = 1;
			}

			Irssi::statusbar_items_redraw('daumode');
		}

		# Signal handling (for daumode and signal 'send text')

		signal_handling();

		return;
	}

	# MSG (or CTCP ACTION) $output to active channel/query-window

	{
		no strict 'refs';

		$output = $output || '';
		output_text($witem, $witem->{name}, $output);
	}
}

################################################################################
# Subroutines (switches, must not be combined)
################################################################################

sub switch_babble {
	my ($data, $channel) = @_;
	my $text;

	# If the remote feature or a previous --babble is babbling: exit

	return if (defined($misc{remote_babble_timer_writing}));
	return if (defined($misc{switch_babble_timer_writing}));

	# get text from file

	$text = &babble_get_text($channel);

	# babble only in channels

	unless (defined($channel) && $channel && $channel->{type} eq 'CHANNEL') {
		print_out('%9--babble%9 will only work in channel windows!');
		return;
	}

	# These are some global variables for the writing timer

	$misc{timer_switch_babble_writing}{channelname}    = $channel->{name};
	$misc{timer_switch_babble_writing}{channel}        = $channel;
	$misc{timer_switch_babble_writing}{counter}        = 0;
	$misc{timer_switch_babble_writing}{text}           = "$text\n";
	$misc{timer_switch_babble_writing}{numberoflines}  = 0;
	$misc{timer_switch_babble_writing}{numberoflines}++ while ($misc{timer_switch_babble_writing}{text} =~ /\n/g);
	$misc{timer_switch_babble_writing}{numberoflines} -= 1;

	Irssi::timeout_remove($misc{remote_switch_babble_timer}) if (defined($misc{remote_switch_babble_timer}));
	timer_switch_babble_writing_reset();

	return;
}

sub switch_changelog {
	my $output;
	$misc{'print'} = 1;

	$output = &fix(<<"	END");
	CHANGELOG

	2002-05-05    release 0.1.0
	              initial release

	2002-05-06    release 0.1.1
	              bugfixes, minor changes

	2002-05-11    release 0.2.0
	              - new function: Put a single space after each character
	              - %9--moron%9: minor changes

	2002-05-12    release 0.3.0
	              new function: %9--mixedcase%9

	2002-05-17    release 0.4.0
	              function putting a single space after each character
	              changed name to %9--delimiter%9 and will accept any
	              delimiter string now

	2002-05-20    release 0.4.1
	              some nice new substitutions for %9--moron%9

	2002-05-24    release 0.5.0
	              new settings controlling the behaviour of %9--figlet%9

	2002-06-15    release 0.6.0
	              - new settings for %9--figlet%9
	              - %9--figlet%9 will omit lines only containing whitespace

	2002-06-16    release 0.6.1
	              bugfixes

	2002-06-16    release 0.6.2
	              bugfixes

	2002-06-17    release 0.7.0
	              - new settings for %9--moron%9
	              - new substitutions for %9--moron%9

	2002-06-19    release 0.8.0
	              new function: %9--dots%9
	              %9--moron%9: minor changes

	2002-06-23    release 0.9.0
	              - new: remote feature
	              - new substitutions for %9--moron%9
	              - %9--figlet%9: bugfixes

	2002-06-23    release 0.9.1
	              - %9--moron%9: minor changes
	              - remote feature: minor changes

	2002-06-29    release 0.9.2
	              new settings for the remote feature

	2002-07-23    release 0.9.3
	              new setting for %9--words%9

	2002-07-28    release 1.0.0
	              - Syntax changed
	              - Tabcompletion for the options
	              - Integrated help (%9--help%9)
	              - Integrated changelog (%9--changelog%9)
	              - Some of the options and settings have a different name
	                now
	              - %9--moron%9 no longer tears smilies apart
	              - new function: %9--leet%9
	              - new function: %9--reverse%9

	2002-07-28    release 1.0.1
	              bugfixes

	2002-09-01    release 1.0.2
	              - the script will now work properly even if the alias for
	                SAY does not exist
	              - new substitutions for %9--moron%9

	2002-09-03    release 1.0.3
	              - bugfixes
	              - new option for %9--figlet%9: %9-font%9

	2002-09-03    release 1.0.4
	              bugfixes

	2002-09-03    release 1.0.5
	              bugfixes

	2002-09-09    release 1.1.0
	              - You can combine commands now!
	              - new substitutions for %9--moron%9
	              - bugfixes

	2002-11-22    release 1.2.0
	              - _A lot_ of rewriting
	              - Syntax for %9${k}dau%9's options changed. See %9${k}dau --help%9
	              - Some settings have changed their name and/or expect other
	                values.
	                Checkout %9${k}dau --help%9, %9${k}set dau_%9 and
	                %9${k}dau --help <setting>%9
	              - new option for %9--delimiter%9: %9-string%9
	              - new option for %9--moron%9: %9-eol%9
	              - new option for %9--moron%9: %9-perm%9
	              - new setting: %9dau_moron_eol_style%9
	              - new setting: %9dau_random_options%9
	              - new setting: %9dau_standard_messages%9
	              - new setting: %9dau_standard_options%9
	              - new remote features:
	                - new setting: %9dau_remote_question_reply%9
	                - new setting: %9dau_remote_voice_reply%9
	                - new setting: %9dau_remote_devoice_reply%9
	                - new setting: %9dau_remote_op_reply%9
	                - new setting: %9dau_remote_deop_reply%9
	              - new function: %9--color%9
	              - new function: %9--daumode%9
	              - new function: %9--random%9
	              - new function: %9--stutter%9
	              - new function: %9--uppercase%9
	              - new statusbar item: %9daumode%9

	2002-11-27    release 1.2.1
	              minor changes and one crash-fix

	2002-12-15    release 1.2.2
	              - Changing settings of 'hallo wie geht'-remote-feature
	                didn't become effective immediately
	              - new substitutions for %9--moron%9

	2003-01-12    release 1.3.0
	              - %9--moron%9: randomly transpose letters with letters
	                next to them at the keyboard
	              - %9--moron%9: new 'substitution-level'. Checkout
	                %9${k}dau --help -setting dau_moron_substitutions_permissions%9
	                and set a new value for this setting
	              - new substitutions for %9--moron%9
	              - new option for %9--moron -eol%9 resp. setting
	                %9dau_moron_eol_style%9: %9nothing%9
	              - new option for %9--moron%9: %9-uppercase%9
	              - new setting: %9dau_files_moron_own_substitutions%9
	              - new setting: %9dau_files_root_directory%9
	              - new function: %9--create_files%9

	2003-01-17    release 1.4.0
	              - %9--color%9 revised
	              - You'll have to specify the ircnet in dau_remote_channellist
	                now. Checkout %9${k}dau --help -setting dau_remote_channellist%9
	              - You'll have to set a new value for dau_remote_permissions
	                too. Checkout %9${k}dau --help -setting dau_remote_permissions%9
	              - new remote features:
	                - new setting: %9dau_remote_babble_interval%9
	              - new function: %9--greet%9

	2003-01-18    release 1.4.1
	              crash-fix

	2003-01-20    release 1.4.2
	              - new setting: %9dau_statusbar_daumode_hide_when_off%9
	              - some other (minor) changes

	2003-02-01    release 1.4.3
	              a few minor changes

	2003-02-09    release 1.4.4
	              - commandline-parsing fixes
	              - some other (minor) changes

	2003-02-16    release 1.4.5
	              - commandline-parsing fixes
	              - many settings use now a comma spearated list of strings instead
	                of one single string. So you can specify more replies for the
	                remote features f.e.

	2003-03-16    release 1.4.6
	              a few minor changes

	2003-05-01    release 1.5.0
	              - almost all signal handlers are now added/removed
	                dynamically. The timer-subroutine for the babble-feature
	                will be entered less often too. So dau.pl will take less
	                CPU-time.
	              - new setting: %9dau_tab_completion%9
	              - new function: %9--bracket%9

	2003-06-13    release 1.5.1
	              - fixed a few bugs. dau.pl should work now pretty good under
	                the warnings pragma.
	              - new function: %9--underline%9

	2003-07-16    release 1.5.2
	              - new function: %9--boxes%9
	              - some other (minor) changes

	2003-08-16    release 1.5.3
	              changes in %IRSSI

	2003-09-14    release 1.5.4
	              - Give figlet the input to play with over STDIN to avoid
	                a figlet bug with strings starting with a dash.
	              - some other (minor) changes

	2003-11-16    release 1.6.0
	              - dau_remote:
	                - reply to a 'hallo wie geht @ yournick'
	                - reply to a colored 'hallo wie geht'
	              - Incoming messages can be dauified now!
	                Checkout %9${k}dau --help%9 (daumode)
	              - Statusbaritem changed. Remove old stuff from your theme-file
	                and look in the documentation of the daumode
	              - some other (minor) changes

	2004-03-25    release 1.7.0
	              - new substitutions for %9--moron%9
	              - new setting: %9dau_babble_standard_options%9
	              - new setting: %9dau_cowsay_cowlist%9
	              - new setting: %9dau_cowsay_cowpath%9
	              - new setting: %9dau_cowsay_cowpolicy%9
	              - new setting: %9dau_cowsay_cowsay_path%9
	              - new setting: %9dau_files_babble_messages%9
	              - new function: %9--cowsay%9
	              - new function: %9--mix%9 (by Martin Kihlgren <zond\@troja.ath.cx>)
	              - new option for %9--color%9: %9-split paragraph%9
	              - new option for %9--command%9: %9-in%9
	              - renamed %9--command -cmd%9 to %9--command -out%9, adjust your
	                aliases etc.
	              - new option for %9--moron%9: %9-omega%9

	2004-04-01    release 1.7.1
	              - new substitutions for %9--moron%9
	              - new setting: %9dau_remote_babble_channellist%9
	              - new setting: %9dau_remote_babble_channelpolicy%9
	              - new setting: %9dau_remote_babble_interval_accuracy%9
	              - new special metasequences for the babble messages.
	                Checkout %9${k}dau --help -setting dau_files_babble_messages%9
	              - %9--command -in%9: bugfix (do not send the original message
	                before the dauified message)

	2004-04-02    release 1.7.2
	              - performance tweaks
	              - babble feature:
	                - bugfix: do not block irssi while writing
	                - better method calculating the writing breaks in
	                  multiline messages. The longer the next line is the
	                  longer the break will be

	2004-04-05    release 1.7.3
	              remote babble feature: bugfix

	2004-05-01    release 1.8.0
	              - new function: %9--babble%9
	              - %9--help%9 revised
	              - new special metasequence for the babble messages.
	                Checkout %9${k}dau --help -setting dau_files_babble_messages%9

	2004-06-24    release 1.8.1
	              - new setting: %9dau_babble_verbose%9
	              - new setting: %9dau_babble_verbose_minimum_lines%9

	2004-07-10    release 1.8.2
	              - new special metasequences for the babble messages.
	                Checkout %9${k}dau --help -setting dau_files_babble_messages%9
	              - try harder to determine the exact amount of lines in the babble
	                verbose information

	2004-07-25    release 1.8.3
	              - fixed crash when the statusbar item had to handle some
	                kind of window
	              - remote feature: do not thank for +o if you already have
	                op etc.

	2004-09-14    release 1.8.4
	              bugfixes

	2004-10-18    release 1.8.5
	              bugfixes

	2004-11-07    release 1.8.6
	              minor changes

	2005-01-28    release 1.9.0
	              - babble bugfixes
	              - new setting: %9dau_cowsay_cowthink_path%9
	              - new option for %9--cowsay%9: %9-arguments%9
	              - new option for %9--cowsay%9: %9-think%9
	END

	return $output;
}

sub switch_create_files {

	# create directory dau_files_root_directory if not found

	if (-f $option{dau_files_root_directory}) {
		print_err("$option{dau_files_root_directory} is a _file_ => aborting");
		return;
	}
	if (-d $option{dau_files_root_directory}) {
		print_out('directory dau_files_root_directory already exists - no need to create it');
	} else {
		if (mkpath([$option{dau_files_root_directory}])) {
			print_out("creating directory $option{dau_files_root_directory}/");
		} else {
			print_err("failed creating directory $option{dau_files_root_directory}/");
		}
	}

	# create file dau_files_moron_own_substitutions if not found

	my $file1 = "$option{dau_files_root_directory}/$option{dau_files_moron_own_substitutions}";

	if (-e $file1) {

		print_out("file $file1 already exists - no need to create it");

	} else {

		if (open(FH1, "> $file1")) {

			print FH1 &fix(<<'			END');
			# dau.pl - http://dau.pl/
			#
			# This is the file --moron will use for your own substitutions.
			# You can use any perlcode in here.
			# $_ contains the text you can work with.
			# $_ has to contain the data to be returned to dau.pl at the end.
			END

			print_out("$file1 created. you should edit it now!");

		} else {

			print_err("cannot write $file1: $!");

		}

		if (!close(FH1)) {
			print_err("cannot close $file1: $!");
		}
	}

	# create file dau_files_babble_messages if not found

	my $file2 = "$option{dau_files_root_directory}/$option{dau_files_babble_messages}";

	if (-e $file2) {

		print_out("file $file2 already exists - no need to create it");

	} else {

		if (open(FH1, "> $file2")) {

			print FH1 &fix(<<'			END');
			END

			print_out("$file2 created. you should edit it now!");

		} else {

			print_err("cannot write $file2: $!");

		}

		if (!close(FH1)) {
			print_err("cannot close $file2: $!");
		}
	}

	return;
}

sub switch_daumode {
	$misc{daumode} = 1;
}

sub switch_help {
	my $output;
	my $option_setting = return_option('help', 'setting');
	$misc{'print'} = 1;

	if ($option_setting eq '') {
		$output = &fix(<<"		END");
		%9SYNOPSIS%9

		%9${k}dau [%Uoptions%U] [%Utext%U%9]

		%9DESCRIPTION%9

		dau? What does that mean?

		DAU /dow/ n.

		[German FidoNet] German acronym for Dmmster Anzunehmender User
		(stupidest imaginable user). From the engineeringslang GAU for Grsster
		Anzunehmender Unfall, worst assumable accident, esp. of a LNG tank farm plant
		or something with similarly disastrous consequences. In popular German, GAU is
		used only to refer to worst-case nuclear acidents such as a core meltdown. See
		cretin, fool, loser and weasel.

		With dau.pl every normal person can write like an idiot on the IRC.

		%9OPTIONS%9

		%9--babble%9
		     Force a babble message (Look further down for more information
		     in the section of the remote features)

		%9--boxes%9
		     Put words in boxes

		%9--bracket%9
		     Bracket the text

		%9--changelog%9
		     Print the scripts changelog

		%9--chars%9
		     Only one character each line

		%9--color%9
		     Write in colors

		     %9-split%9:
		          %Uchars%U:      Every character another color
		          %Ulines%U:      Every line another color
		          %Uparagraph%U:  The whole paragraph in one color
		          %Urchars%U:     Some characters one color
		          %Uwords%U:      Every word another color

		%9--command%9
		     %9-in%9 %Ucommand%U:
		          Feed dau.pl with the output (the public message)
		          that %Ucommand%U produces

		     %9-out%9 %Ucommand%U:
		          %Utopic%U for example will set a dauified topic

		%9--cowsay%9
		     Use cowsay to write

		     %9-arguments%9 %Uarguments%U:
		          Pass any option to cowsay, f.e. '-b' or '-e XX'.
		          Look in the cowsay manualpage for details.
		     %9-cow%9 %Ucow%U:
		          The cow to use.
		     %9-think%9 %Uyes|no%U:
		          Think instead of speaking.

		%9--create_files%9
		     Create files and directories of all dau_files_*-settings

		%9--daumode%9
		     Toggle daumode.
		     Works on a per channel basis!

		     %9-imodes%9 %Umodes%U:
		          All incoming messages will be dauified and the
		          specified modes are used by dau.pl. If you omit these
		          option, dau.pl will use the standard options.

		     %9-omodes%9 %Umodes%U:
		          All outgoing messages will be dauified and the
		          specified modes are used by dau.pl. If you omit these
		          option, dau.pl will use the standard options.

		     %9-perm%9 %U[01][01]%U:
		          Dauify incoming/outgoing messages?

		     There is a statusbar item available displaying the current
		     status of the daumode. Add it with
		     %9/statusbar <bar> add [-alignment <left|right>] daumode%9
		     You may customize the look of the statusbar item in the
		     theme file. f.e.:

		     sb_daumode = "{sb daumode I: \$0 (\$1) O: \$2 (\$3)}";

		     # \$0: will incoming messages be dauified?
		     # \$1: modes for incoming messages
		     # \$2: will outgoing messages be dauified?
		     # \$3: modes for outgoing messages

		%9--delimiter%9
		     Insert a delimiter-string after each character

		     %9-string%9 %Ustring%U:
		          Override setting dau_delimiter_string. If this string
		          contains whitespace, you should quote the string with
		          single quotes.

		%9--dots%9
		     Put some dots... after some words...

		%9--figlet%9
		     Use figlet to write

		     %9-font%9 %Ufont%U:
		          The font to use

		%9--greet%9
		     Greet people in channel

		     %9-whom%9 %Uall|rnick%U:
		          %Uall%U  : every nick
		          %Urnick%U: one nick randomly selected

		%9--help%9
		     Show these lines

		     %9-setting%9 %Usetting%U:
		          More information about a specific setting

		%9--leet%9
		     Write in leet speech

		%9--me%9
		     Send a CTCP ACTION instead of a PRIVMSG

		%9--mix%9
		     Mix all the characters in a word except for the first and
		     last

		%9--mixedcase%9
		     Write in mixed case

		%9--moron%9
		     Write in uppercase, mix in some typos, perform some
		     substitutions on the text, ... Just write like a
		     moron

		     %9-eol%9 %Uclassic|new|nothing%U:
		          Override setting dau_moron_eol_style

		     %9-omega%9 %Uyes|no%U:
		          The fantastic omega mode

		     %9-perm%9 %U[01][01][01]%U:
		          Override setting dau_moron_substitutions_permissions

		     %9-uppercase%9 %Uyes|no%U:
		          Uppercase text

		%9--nothing%9
		     Do nothing

		%9--random%9
		     Let dau.pl choose randomly options. Get these options from
		     the comma separated list of setting dau_random_options

		%9--reverse%9
		     Reverse the input string

		%9--stutter%9
		     Stutter a bit

		%9--underline%9
		     Underline text

		%9--uppercase%9
		     Write in upper case

		%9--words%9
		     Only a few words each line

		%9EXAMPLES%9

		%9${k}dau --uppercase --mixedcase %Ufoo bar baz%9
		     Will write %Ufoo bar baz%U in mixed case.
		     %Ufoo bar baz%U is sent _first_ to the uppercase
		     subroutine _then_ to mixedcase subroutine. The order you
		     specify the options on the commandline is important. You
		     can see what output a command produces without sending it
		     to the active channel/query-window by typing the command
		     out of a non-channel/query-window. There are thousands of
		     possiblilities combining the options, so some combinations
		     may produce a strange output. Try changing the order of
		     the options, that might help.

		%9${k}dau --color --figlet %Ufoo bar baz%9
		     %9--color%9 will insert colorcodes after some characters.
		     So the string will look like %U\\00302f\\00303o[...]%U when
		     leaving the color subroutine. %9--figlet%9 uses then that
		     string as its input. So you'll have finally an output like
		     %U02f03o[...]%U in the figlet latters.
		     So its better to use _first_ %9--figlet%9 _then_ %9--color%9.

		%9SPECIAL FEATURES%9

		%9Combine the options%9
		     You can combine most of the options! So you can write colored
		     leet messages f.e.. Look in the EXAMPLES section above.

		%9Daumode%9
		     Dauify incoming and/or outgoing messages. There is a
		     statusbaritem available indicating the status. Scroll up
		     and look at the documentation for %9--daumode%9 to find out
		     more!

		%9Remote features%9
		     Don't worry, it will do _nothing_ automatically unless
		     _you_ unlock these features!

		     %9Babble%9
		          Babble crap in some channels in intervals.

		          Related settings:

		          %9dau_babble_standard_options%9
		          %9dau_files_babble_messages%9
		          %9dau_files_root_directory%9
		          %9dau_remote_babble_channellist%9
		          %9dau_remote_babble_channelpolicy%9
		          %9dau_remote_babble_interval%9
		          %9dau_remote_babble_interval_accuracy%9
		          %9dau_remote_permissions%9

		          Read the information for each setting to find out more:
		          %9${k}dau --help -setting %Usetting%U%9

		          Related switches:

		          %9--babble%9
		          %9--create_files%9

		     %9Reply to the question 'hallo wie geht?'%9
		          Well, that's something only for german users. I included it
		          for a channel i'm in, we wanted to have it. I don't know if
		          anyone else on earth wants to use it.

		          Related settings:

		          %9dau_remote_channellist%9
		          %9dau_remote_channelpolicy%9
		          %9dau_remote_permissions%9
		          %9dau_remote_question_reply%9

		          Read the information for each setting to find out more:
		          %9${k}dau --help -setting %Usetting%U%9

		     %9Say something on (de)op/(de)voice%9
		          Related settings:

		          %9dau_remote_channellist%9
		          %9dau_remote_channelpolicy%9
		          %9dau_remote_deop_reply%9
		          %9dau_remote_devoice_reply%9
		          %9dau_remote_op_reply%9
		          %9dau_remote_permissions%9
		          %9dau_remote_voice_reply%9

		          Read the information for each setting to find out more:
		          %9${k}dau --help -setting %Usetting%U%9

		%9TAB Completion%9
		     There is a really clever TAB Completion included! Since
		     commands can get very long you definitely want to use it.
		     It will only complete syntactic correct commands so the
		     TAB Completion isn't only a time saver, it's a control
		     instance too. You'll be suprised to see that it even completes
		     the figlet fonts and cows for cowsay that are available on
		     your system.

		%9Website%9
		     Visit $IRSSI{url} for more information about dau.pl.
		     You'll find there the dauomat and the dauproxy for www dau
		     fun.
		END
	}

	# setting changed/added => change/add them below

	# boolean

	elsif ($option_setting eq 'dau_babble_verbose') {
		$output = &fix(<<"		END");
		%9dau_babble_verbose%9 %Ubool

		Before babbling print a message how many lines will be babbled and
		when finished a notification message.
		END
	}
	elsif ($option_setting eq 'dau_cowsay_print_cow') {
		$output = &fix(<<"		END");
		%9dau_cowsay_print_cow%9 %Ubool

		Print a message which cow will be used.
		END
	}
	elsif ($option_setting eq 'dau_figlet_print_font') {
		$output = &fix(<<"		END");
		%9dau_figlet_print_font%9 %Ubool

		Print a message which font will be used.
		END
	}
	elsif ($option_setting eq 'dau_statusbar_daumode_hide_when_off') {
		$output = &fix(<<"		END");
		%9dau_statusbar_daumode_hide_when_off%9 %Ubool

		Hide statusbar item when daumode is turned off.
		END
	}
	elsif ($option_setting eq 'dau_tab_completion') {
		$output = &fix(<<"		END");
		%9dau_tab_completion%9 %Ubool

		Perhaps someone wants to disable TAB-Completion for the
		${k}dau-command because he/she doesn't like it or wants
		to give the CPU a break (don't know whether it has much
		influence)
		END
	}

	# Integer

	elsif ($option_setting eq 'dau_babble_verbose_minimum_lines') {
		$output = &fix(<<"		END");
		%9dau_babble_verbose_minimum_lines%9 %Uinteger

		Minimum lines necessary to produce the output of the verbose
		information.
		END
	}
	elsif ($option_setting eq 'dau_remote_babble_interval') {
		$output = &fix(<<"		END");
		%9dau_remote_babble_interval%9 %Uinteger

		Interval (in seconds) dau.pl will babble text.
		END
	}
	elsif ($option_setting eq 'dau_remote_babble_interval_accuracy') {
		$output = &fix(<<"		END");
		%9dau_remote_babble_interval_accuracy%9 %Uinteger

		Value expressed as a percentage how accurate the timer of
		the babble feature should be.

		Legal values: 1-100

		%U100%U would result in a very accurate timer.
		END
	}

	# String

	elsif ($option_setting eq 'dau_babble_standard_options') {
		$output = &fix(<<"		END");
		%9dau_babble_standard_options%9 %Ustring

		Options babble will use if the user omits them.
		END
	}
	elsif ($option_setting eq 'dau_cowsay_cowlist') {
		$output = &fix(<<"		END");
		%9dau_cowsay_cowlist%9 %Ustring

		Comma separated list of cows. Checkout
		%9${k}dau --help -setting dau_cowsay_cowpolicy%9
		to see what this setting is good for.
		END
	}
	elsif ($option_setting eq 'dau_cowsay_cowpath') {
		$output = &fix(<<"		END");
		%9dau_cowsay_cowpath%9 %Ustring

		Path to the cowsay-cows (*.cow).
		END
	}
	elsif ($option_setting eq 'dau_cowsay_cowpolicy') {
		$output = &fix(<<"		END");
		%9dau_cowsay_cowpolicy%9 %Ustring

		Specifies the policy used to handle the cows in
		dau_cowsay_cowpath. If set to %Uallow%U, all cows available
		will be used by the command. You can exclude some cows by
		setting dau_cowsay_cowlist. If set to %Udeny%U, no cows but
		the ones listed in dau_cowsay_cowlist will be used by the
		command. Useful if you have many annoying cows in your
		cowpath and you want to permit only a few of them.
		END
	}
	elsif ($option_setting eq 'dau_cowsay_cowsay_path') {
		$output = &fix(<<"		END");
		%9dau_cowsay_cowsay_path%9 %Ustring

		Should point to the cowsay executable.
		END
	}
	elsif ($option_setting eq 'dau_cowsay_cowthink_path') {
		$output = &fix(<<"		END");
		%9dau_cowsay_cowthink_path%9 %Ustring

		Should point to the cowthink executable.
		END
	}
	elsif ($option_setting eq 'dau_delimiter_string') {
		$output = &fix(<<"		END");
		%9dau_delimiter_string%9 %Ustring

		Tell %9--delimiter%9 which delimiter to use.
		END
	}
	elsif ($option_setting eq 'dau_figlet_fontlist') {
		$output = &fix(<<"		END");
		%9dau_figlet_fontlist%9 %Ustring

		Comma separated list of fonts. Checkout
		%9${k}dau --help -setting dau_figlet_fontpolicy%9
		to see what this setting is good for. Use the program
		`showfigfonts` shipped with figlet to find these fonts.
		END
	}
	elsif ($option_setting eq 'dau_figlet_fontpath') {
		$output = &fix(<<"		END");
		%9dau_figlet_fontpath%9 %Ustring

		Path to the figlet-fonts (*.flf).
		END
	}
	elsif ($option_setting eq 'dau_figlet_fontpolicy') {
		$output = &fix(<<"		END");
		%9dau_figlet_fontpolicy%9 %Ustring

		Specifies the policy used to handle the fonts in
		dau_figlet_fontpath. If set to %Uallow%U, all fonts available
		will be used by the command. You can exclude some fonts by
		setting dau_figlet_fontlist. If set to %Udeny%U, no fonts but
		the ones listed in dau_figlet_fontlist will be used by the
		command. Useful if you have many annoying fonts in your
		fontpath and you want to permit only a few of them.
		END
	}
	elsif ($option_setting eq 'dau_figlet_path') {
		$output = &fix(<<"		END");
		%9dau_figlet_path%9 %Ustring

		Should point to the figlet executable.
		END
	}
	elsif ($option_setting eq 'dau_files_babble_messages') {
		$output = &fix(<<"		END");
		%9dau_files_babble_messages%9 %Ustring

		The file with the babble messages.
		_Must_ be in dau_files_root_directory.
		%9${k}dau --create_files%9 will create it.

		Format of the file:
		    Newline separated plain text.

		    Special Metasequences:

		    - \\n:
		      real newline
		    - \$nick1 ... \$nickN:
		      N different randomly selected nicks
		    - \$opnick1 ... \$opnickN:
		      N different randomly selected opnicks
		    - \$rnick:
		      one random nick
		    - \$?{ code }:
		      the (perl)code will be evaluated and the last expression
		      returned will replace that metasequence
		    - irssis special variables like \$C for the current
		      channel and \$N for your current nick

		    Quoting:

		    - \\\$: literal \$
		    - \\\\: literal \\
		END
	}
	elsif ($option_setting eq 'dau_files_moron_own_substitutions') {
		$output = &fix(<<"		END");
		%9dau_files_moron_own_substitutions%9 %Ustring

		Your own substitutions-file (third bit setting
		dau_moron_substitutions_permissions). _Must_ be in
		dau_files_root_directory.
		%9${k}dau --create_files%9 will create it.
		END
	}
	elsif ($option_setting eq 'dau_files_root_directory') {
		$output = &fix(<<"		END");
		%9dau_files_root_directory%9 %Ustring

		Directory in which all files for dau.pl will be stored.
		%9${k}dau --create_files%9 will create it.
		END
	}
	elsif ($option_setting eq 'dau_moron_eol_style') {
		$output = &fix(<<"		END");
		%9dau_moron_eol_style%9 %Ustring

		What to do at End Of Line?

		%Uclassic%U: !!!??!!!!!????!??????????!!!1 (or similar)
		%Unew%U    : !!!??!!!!!????!??????????!!!1 (or similar) or
		         = and in a new line ?                      or
		         ??
		%Unothing%U: nothing at EOL
		END
	}
	elsif ($option_setting eq 'dau_moron_substitutions_permissions') {
		$output = &fix(<<"		END");
		%9dau_moron_substitutions_permissions%9 %U[01][01][01]

		Controls whether %9--moron%9 should perform some
		substitutions on the text or not. These substitutions make
		only sense performed on german text.

		First Bit:
		    You should turn it on if you write german text with dau.pl

		Second Bit:
		    Perform substitutions which may cause that a third person
		    does not understand what you wanted to say.
		    Anyway, most user i know have turned it on

		Third Bit:
		    Your own substitutions. Checkout the help for the
		    dau_files_*-settings and %9--create_files%9
		END
	}
	elsif ($option_setting eq 'dau_random_options') {
		$output = &fix(<<"		END");
		%9dau_random_options%9 %Ustring

		Comma separated list of options %9--random%9 will use. It will
		take randomly one item of the list. If you set it f.e. to
		%U--uppercase --color,--mixedcase%U,
		the probability of printing a colored, uppercased string hello
		will be 50% as well as the probabilty of printing a mixedcased
		string hello when typing %9${k}dau --random hello%9.
		END
	}
	elsif ($option_setting eq 'dau_remote_babble_channellist') {
		$output = &fix(<<"		END");
		%9dau_remote_babble_channellist%9 %Ustring

		Comma separated list of channels. You'll have to specify the
		ircnet too.
		Format: #channel1/IRCNet,#channel2/EFnet
		END
	}
	elsif ($option_setting eq 'dau_remote_babble_channelpolicy') {
		$output = &fix(<<"		END");
		%9dau_remote_babble_channelpolicy%9 %Ustring

		Using the default policy %Udeny%U the script won't do anything
		except in the channels listed in dau_remote_babble_channellist.
		Using the policy %Uallow%U the script will babble in all
		channels but the ones listed in dau_remote_babble_channellist.
		END
	}
	elsif ($option_setting eq 'dau_remote_channellist') {
		$output = &fix(<<"		END");
		%9dau_remote_channellist%9 %Ustring

		Comma separated list of channels. You'll have to specify the
		ircnet too.
		Format: #channel1/IRCNet,#channel2/EFnet
		END
	}
	elsif ($option_setting eq 'dau_remote_channelpolicy') {
		$output = &fix(<<"		END");
		%9dau_remote_channelpolicy%9 %Ustring

		Using the default policy %Udeny%U the script won't do anything
		except in the channels listed in dau_remote_channellist. Using
		the policy %Uallow%U the script will reply to all channels but
		the ones listed in dau_remote_channellist.
		END
	}
	elsif ($option_setting eq 'dau_remote_deop_reply') {
		$output = &fix(<<"		END");
		%9dau_remote_deop_reply%9 %Ustring

		Comma separated list of messages (it will take randomly one
		item of the list) sent to channel if someone deops you (mode
		change -o).
		The string given will be processed by the same subroutine
		parsing the %9${k}dau%9 command.

		Special Variables:

		\$nick: contains the nick of the one who changed the mode
		END
	}
	elsif ($option_setting eq 'dau_remote_devoice_reply') {
		$output = &fix(<<"		END");
		%9dau_remote_devoice_reply%9 %Ustring

		Comma separated list of messages (it will take randomly one
		item of the list) sent to channel if someone devoices you (mode
		change -v).
		The string given will be processed by the same subroutine
		parsing the %9${k}dau%9 command.

		Special Variables:

		\$nick: contains the nick of the one who changed the mode
		END
	}
	elsif ($option_setting eq 'dau_remote_op_reply') {
		$output = &fix(<<"		END");
		%9dau_remote_op_reply%9 %Ustring

		Comma separated list of messages (it will take randomly one
		item of the list) sent to channel if someone ops you (mode
		change +o).
		The string given will be processed by the same subroutine
		parsing the %9${k}dau%9 command.

		Special Variables:

		\$nick: contains the nick of the one who changed the mode
		END
	}
	elsif ($option_setting eq 'dau_remote_permissions') {
		$output = &fix(<<"		END");
		%9dau_remote_permissions%9 %U[01][01][01][01][01][01]

		Permit or forbid the remote features.

		First Bit:
		    Very, very useful feature. Will reply to the profound question
		    'hallo wie geht?' the appropriate answer.
		    Again, only useful for german users. ;-)

		Second Bit:
		    If someone gives you voice in a channel, thank him!

		Third Bit:
		    If someone gives you op in a channel, thank him!

		Fourth Bit:
		    If devoiced, print message

		Fifth Bit:
		    If deopped, print message

		Sixth Bit:
		    Babble text in certain intervals
		END
	}
	elsif ($option_setting eq 'dau_remote_question_reply') {
		$output = &fix(<<"		END");
		%9dau_remote_question_reply%9 %Ustring

		Comma separated list of reply strings for the question 'hallo
		wie geht?' (it will randomly choose one item of the list).
		The string given will be processed by the same subroutine
		parsing the %9${k}dau%9 command.

		Special Variables:

		\$nick: contains the nick of the one who sent the message to which
		       dau.pl reacts
		END
	}
	elsif ($option_setting eq 'dau_remote_voice_reply') {
		$output = &fix(<<"		END");
		%9dau_remote_voice_reply%9 %Ustring

		Comma separated list of messages (it will take randomly one
		item of the list) sent to channel if someone voices you (mode
		change +v).
		The string given will be processed by the same subroutine
		parsing the %9${k}dau%9 command.

		Special Variables:

		\$nick: contains the nick of the one who changed the mode
		END
	}
	elsif ($option_setting eq 'dau_standard_messages') {
		$output = &fix(<<"		END");
		%9dau_standard_messages%9 %Ustring

		Comma separated list of strings %9${k}dau%9 will use if the user
		omits the text on the commandline.
		END
	}
	elsif ($option_setting eq 'dau_standard_options') {
		$output = &fix(<<"		END");
		%9dau_standard_options%9 %Ustring

		Options %9${k}dau%9 will use if the user omits them on the commandline.
		END
	}
	elsif ($option_setting eq 'dau_words_range') {
		$output = &fix(<<"		END");
		%9dau_words_range%9 %Ui-j

		Setup the range howmany words the command should write per line.
		1 <= i <= j <= 9; i, j element { 1, ... , 9 }. If i == j the command
		will write i words to the active window.  Else it takes a random
		number k (element { i, ... , j }) and writes k words per
		line.
		END
	}

	return $output;
}

sub switch_random {
	my ($data, $channel_rec) = @_;
	my $output;
	my (@options, $text);

	# Push each item of dau_random_options in the @options array.

	while ($option{dau_random_options} =~ /\s*([^,]+)\s*,?/g) {
		my $item = $1;
		push @options, $item;
	}

	# More than one item in @options. Choose one randomly but exclude
	# the last item chosen.

	if (@options > 1) {
		@options = grep { $_ ne $misc{random_last} } @options;
		my $opt = @options[rand(@options)];
		$misc{random_last} = $opt;
		$text .= $opt . ' ' . $data;
		$output = parse_text($text, $channel_rec);
	}

	# Exact one item in @options - take that

	elsif (@options == 1) {
		my $opt = $options[0];
		$misc{random_last} = $opt;
		$text .= $opt . ' ' . $data;
		$output = parse_text($text, $channel_rec);
	}

	# No item in @options - call switch_moron()

	else {
		$output = &{ $switches{combo}{moron}{'sub'} }($output, $channel_rec);
	}

	return $output;
}

################################################################################
# Subroutines (switches, may be combined)
################################################################################

sub switch_boxes {
	my $data = shift;

	# handling punctuation marks:
	# they will be put in their own box later

	$data =~ s%(\w+)([,.?!;:]+)%
	           $1 . ' ' . join(' ', split(//, $2))
	          %egx;

	# separate words (by whitespace) and put them in a box

	$data =~ s/(\s*)(\S+)(\s*)/$1\[$2\]$3/g;

	return $data;
}

sub switch_bracket {
	my $data = shift;
	my $output;

	my %brackets = (
                        '(('   => '))',
                        '-=('  => ')=-',
                        '-=['  => ']=-',
                        '-={'  => '}=-',
                        '-=|(' => ')|=-',
                        '-=|[' => ']|=-',
                        '-=|{' => '}|=-',
                        '.:>'  => '<:.',
                       );

	foreach (keys %brackets) {
		for my $times (2 .. 3) {
			my $pre  = $_;
			my $post = $brackets{$_};
			$pre  =~ s/(.)/$1 x $times/eg;
			$post =~ s/(.)/$1 x $times/eg;

			$brackets{$pre} = $post;
		}
	}

	$brackets{'!---?['} = ']?---!';
	$brackets{'(qp=>'}  = '<=qp)';
	$brackets{'----->'} = '<-----';

	my $pre = (keys(%brackets))[int(rand(keys(%brackets)))];
	my $post = $brackets{$pre};

	$output = "$pre $data $post";

	return $output;
}

sub switch_chars {
	my $data = shift;
	my $output;

	foreach my $char (split //, $data) {
		$output .= "$char\n";
	}
	return $output;
}

sub switch_command {
	my ($data, $channel_rec) = @_;

	# -out <command>

	$misc{command_out} = return_option('command', 'out');
	$misc{switch_command_out} = 1;

	# -in <command>

	$misc{command_in} = '';
	my $option_command_in = return_option('command', 'in');

	if ($option_command_in) {
		Irssi::signal_add_first('command msg', 'signal_command_msg');
		$channel_rec->command("$option_command_in $data");
		Irssi::signal_remove('command msg', 'signal_command_msg');
		return $misc{command_in};
	}

	return $data;
}

sub switch_color {
	my $data = shift;
	my (@colors, $option_color_split, $output, $split);
	my @all_colors = qw(2 3 5 6 8 10);

	@all_colors = map { $_ = sprintf('%02d', $_) } @all_colors;

	$option_color_split = return_option('color', 'split', 'words');

	if ($option_color_split eq 'chars') {
		$split = '';
	} elsif ($option_color_split eq 'lines') {
		$split = "\n";
	} elsif ($option_color_split eq 'words') {
		$split = '\s+';
	} elsif ($option_color_split eq 'rchars') {
		$split = '.' x rand(10);
	} elsif ($option_color_split eq 'paragraph') {
		$split = "\n";
	} else {
		$split = '\s+';
	}

	@colors = @all_colors;

	for (split /($split)/, $data) {
		my $color = $colors[rand(@colors)];

		if ($_ eq ',') {
			$output .= "\003" . $color . ',,';
			if ($option_color_split ne 'paragraph') {
				@colors = grep { $_ ne $color } @all_colors;
			} else {
				@colors = ($color);
			}
		} elsif (/^\s*$/) {
			$output .= $_;
		} else {
			$output .= "\003" . $color . $_;
			if ($option_color_split ne 'paragraph') {
				@colors = grep { $_ ne $color } @all_colors;
			} else {
				@colors = ($color);
			}
		}
	}

	return $output;
}

sub switch_cowsay {
	my $data = shift;
	my ($binarypath, $output, @cows, %cow, $cow, @cache1, @cache2);
	my $skip = 1;
	my $think = return_option('cowsay', 'think');

	if ($think eq 'yes') {
		$binarypath = $option{dau_cowsay_cowthink_path};
		unless (-e $binarypath) {
			print_err('cowthink not found. More information: ' .
				  "%9${k}dau --help -setting dau_cowsay_cowthink_path%9");
			return;
		}
	} else {
		$binarypath = $option{dau_cowsay_cowsay_path};
		unless (-e $binarypath) {
			print_err('cowsay not found. More information: ' .
				  "%9${k}dau --help -setting dau_cowsay_cowsay_path%9");
			return;
		}
	}

	if (return_option('cowsay', 'cow')) {
		$cow = return_option('cowsay', 'cow');
	} else {
		while ($option{dau_cowsay_cowlist} =~ /\s*([^,\s]+)\s*,?/g) {
			$cow{$1} = 1;
		}
		foreach my $cow (keys %{ $switches{combo}{cowsay}{cow} }) {
			if (lc($option{dau_cowsay_cowpolicy}) eq 'allow') {
				push(@cows, $cow)
					unless ($cow{$cow});
			} elsif (lc($option{dau_cowsay_cowpolicy}) eq 'deny') {
				push(@cows, $cow)
					if ($cow{$cow});
			} else {
				print_err('Invalid value for setting dau_cowsay_cowpolicy. ' .
				          'More information: ' .
				          "%9${k}dau --help -setting dau_cowsay_cowpolicy%9");
				return;
			}
		}
		if (@cows == 0) {
			print_err('Cannot find cowsay-cows. Please check your cowsay installation ' .
			          "or dau.pl's settings for %9--cowsay%9 (%9${k}set dau_cowsay%9)");
			return;
		}
		$cow = $cows[rand(@cows)];
	}

	# Run cowsay or cowthink

	local(*HIS_IN, *HIS_OUT, *HIS_ERR);
	my @arguments;
	my $option_arguments = return_option('cowsay', 'arguments');
	if ($option_arguments) {
		@arguments = split(/ /, $option_arguments);
	}
	my $childpid = open3(*HIS_IN, *HIS_OUT, *HIS_ERR, $binarypath, '-f', $cow, @arguments);

	print HIS_IN $data or return;
	close(HIS_IN) or return;

	my @errlines = <HIS_ERR>;
	my @outlines = <HIS_OUT>;
	close(HIS_ERR) or return;
	close(HIS_OUT) or return;

	waitpid($childpid, 0);
	if ($?) {
		print_err("That child exited with wait status of $?");
	}

	# Error during execution? Print errors and return

	unless (@errlines == 0) {
		print_err('Error during execution of cowsay');
		foreach my $line (@errlines) {
			print_err($line);
		}
		return;
	}

	if ($option{dau_cowsay_print_cow}) {
		print_out("using cowsay-cow $cow");
	}

	foreach (@outlines) {
		chomp;
		if (/^\s*$/ && $skip) {
			next;
		} else {
			$skip = 0;
		}
		push(@cache1, $_);
	}
	$skip = 1;
	foreach (reverse @cache1) {
		chomp;
		if (/^\s*$/ && $skip) {
			next;
		} else {
			$skip = 0;
		}
		push(@cache2, $_);
	}
	foreach (reverse @cache2) {
		$output .= "$_\n";
	}

	return $output;
}

sub switch_delimiter {
	my $data = shift;
	my $output;
	my $option_delimiter_string = return_option('delimiter', 'string', $option{dau_delimiter_string});

	foreach my $char (split //, $data) {
		$output .= $char . $option_delimiter_string;
	}
	return $output;
}

sub switch_dots {
	my $data = shift;

	$data =~ s/[,;.:?!]*\s+/
	           if (rand(10) < 3) {
	               (rand(10) >= 5 ? ' ' : '')
	               .
	               ('...' . '.' x rand(5))
	               .
	               (rand(10) >= 5 ? ' ' : '')
	           } else { ' ' }
	          /egox;
	rand(10) >= 5 ? $data .= ' ' : 0;
	$data .= ('...' . '.' x rand(10));

	return $data;
}

sub switch_figlet {
	my $data = shift;
	my $skip = 1;
	my ($output, @fonts, %font, $font, @cache1, @cache2);

	unless (-e $option{dau_figlet_path}) {
		print_err('figlet not found. More information: ' .
		          "%9${k}dau --help -setting dau_figlet_path%9");
		return;
	}

	if (return_option('figlet', 'font')) {
		$font = return_option('figlet', 'font');
	} else {
		while ($option{dau_figlet_fontlist} =~ /\s*([^,\s]+)\s*,?/g) {
			$font{$1} = 1;
		}
		foreach my $font (keys %{ $switches{combo}{figlet}{font} }) {
			if (lc($option{dau_figlet_fontpolicy}) eq 'allow') {
				push(@fonts, $font)
					unless ($font{$font});
			} elsif (lc($option{dau_figlet_fontpolicy}) eq 'deny') {
				push(@fonts, $font)
					if ($font{$font});
			} else {
				print_err('Invalid value for setting dau_figlet_fontpolicy. ' .
				          'More information: ' .
				          "%9${k}dau --help -setting dau_figlet_fontpolicy%9");
				return;
			}
		}
		if (@fonts == 0) {
			print_err('Cannot find figlet-fonts. Please check your figlet installation ' .
			          "or dau.pl's settings for %9--figlet%9 (%9${k}set dau_figlet%9)");
			return;
		}
		$font = $fonts[rand(@fonts)];
	}

	# Run figlet

	local(*HIS_IN, *HIS_OUT, *HIS_ERR);

	my $childpid = open3(*HIS_IN, *HIS_OUT, *HIS_ERR, $option{dau_figlet_path}, '-f', $font);

	print HIS_IN $data or return;
	close(HIS_IN) or return;

	my @errlines = <HIS_ERR>;
	my @outlines = <HIS_OUT>;
	close(HIS_ERR) or return;
	close(HIS_OUT) or return;

	waitpid($childpid, 0);
	if ($?) {
		print_err("That child exited with wait status of $?");
	}

	# Error during execution? Print errors and return

	unless (@errlines == 0) {
		print_err('Error during execution of figlet');
		foreach my $line (@errlines) {
			print_err($line);
		}
		return;
	}

	if ($option{dau_figlet_print_font}) {
		print_out("using figlet-font $font");
	}

	foreach (@outlines) {
		chomp;
		if (/^\s*$/ && $skip) {
			next;
		} else {
			$skip = 0;
		}
		push(@cache1, $_);
	}
	$skip = 1;
	foreach (reverse @cache1) {
		chomp;
		if (/^\s*$/ && $skip) {
			next;
		} else {
			$skip = 0;
		}
		push(@cache2, $_);
	}
	foreach (reverse @cache2) {
		$output .= "$_\n";
	}

	return $output;
}

sub switch_greet {
	my $channel = $_[1];
	my (@nicks, $output);

	if (defined($channel) && $channel && $channel->{type} eq 'CHANNEL') {
		foreach my $nick ($channel->nicks()) {
			if ($channel->{server}->{nick} ne $nick->{nick}) {
				push(@nicks, $nick->{nick});
			}
		}
	}

	if (@nicks == 0) {
		return;
	}

	if (return_option('greet', 'whom') eq 'rnick') {
		$output = 'hi @ ' . $nicks[rand(@nicks)];
	} else {
		$output = 'hi @ ';
		@nicks = sort { lc($a) cmp lc($b) } @nicks;
		for my $nick (@nicks) {
			$output .= "$nick, ";
		}
		$output =~ s/, $//;
	}

	return $output;
}

sub switch_leet {
	my $data = shift;

	$_ = $data;
	s'fucker'f@#$er'gi;
	s/hacker/h4x0r/gi;
	s/sucker/sux0r/gi;
	s/fear/ph34r/gi;
	s/dude/d00d/gi;
	s/rude/r00d/gi;
	s/\bthe\b/d4/gi;
	s/\byou\b/j00/gi;
	s/\bdo\b/d00/gi;
	s/\b(\w{3,})er\b/${1}0r/gi;
	tr/lLzZeEaAsSgGtTbBqQoOiIcC/11223344556677889900||((/;
	s/(\w)/rand(100) < 50 ? "\u$1" : "\l$1"/ge;

	return $_;
}

sub switch_me {
	my $data = shift;

	$misc{command_out} = 'ACTION';

	return $data;
}

# &switch_mix by Martin Kihlgren <zond@troja.ath.cx>
# slightly modified by myself

sub switch_mix {
	my $data = shift;
	my $output;

	while ($data =~ s/(\s*)([^\w]*)([\w]+)([^\w]*)(\s+[^\w]*\w+[^\w]*\s*)*/$5/) {
		my $prespace = $1;
		my $prechars = $2;
		my $w = $3;
		my $postchars = $4;
		$output = $output . $prespace . $prechars . substr($w,0,1);
		my $middle = substr($w,1,length($w) - 2);
		while ($middle =~ s/(.)(.*)/$2/) {
			if (rand() > 0.1) {
				$middle = $middle . $1;
			} else {
				$output = $output . $1;
			}
		}
		if (length($w) > 1) {
			$output = $output . substr($w, length($w) - 1, 1);
		}
		$output = $output . $postchars;
	}

	return $output;
}

sub switch_mixedcase {
	my $data = shift;

	$data =~ s/([[:alpha:]])/rand(100) < 50 ? uc($1) : lc($1)/ge;

	return $data;
}

sub switch_moron {
	my ($data, $channel_rec) = @_;
	my $output;
	my $option_eol_style = return_option('moron', 'eol', $option{dau_moron_eol_style});
	my $option_substitutions_permissions = return_option('moron', 'perm', $option{dau_moron_substitutions_permissions});

	# -omega yes

	my $omega;

	if (return_option('moron', 'omega') eq 'yes') {
		my @words = qw(omfg lol wtf);

		foreach (split / (?=\w+\b)/, $data) {
			if (rand(100) < 20) {
				$omega .= ' ' . $words[rand(@words)] . " $_";
			} else {
				$omega .= ' ' . $_;
			}
		}

		$omega =~ s/\s*,\s+\@/ @/g;
		$omega =~ s/^\s+//;
	}

	$_ = $omega || $data;

	# Generate list of nicks in current channel for later use

	my @nicks;

	if (defined($channel_rec) && $channel_rec && $channel_rec->{type} eq 'CHANNEL') {
		foreach my $nick ($channel_rec->nicks()) {
			if ($channel_rec->{server}->{nick} ne $nick->{nick}) {
				push(@nicks, quotemeta($nick->{nick}));
			}
		}
	}

	# Remove puntuation marks at EOL and ensure there is a single space at EOL.
	# This is necessary because the EOL-styles 'new' and 'classic' put them at
	# EOL. If EOL-style is set to 'nothing' don't do this.

	s/\s*([,;.:?!])*\s*$// unless ($option_eol_style eq 'nothing');
	my $lastchar = $1;

	# Only whitespace? Remove it.

	s/^\s+$//;

	# Some substitutions which cannot be turned off

	tr/'/`/;

	# english

	s/\bthe\b/teh/go;

	{
		local $" = '|';
		eval { # Catch strange error
			s/^(@nicks): (.+)/$2 @ $1/;
		};
	}

	{
		# possible asterisks

		my @a = ('*', '');

		# choose one

		my $a = $a[int(rand(@a))];

		# replacement

		s/\*g\*/$a . 'ggg' . ('g' x rand(10)) . $a/egio;
	}

	{
		# Use of uninitialized value in concatenation (.) or string at...
		# (the optional dash ($1) in the regular expressions)

		no warnings;

		if (int(rand(2))) {
			s/:(-)?\)/^^/go;
		} else {
			s/:(-)?\)/':' . $1 . ')))' . (')' x rand(10)) . ('9' x rand(4))/ego;
		}

		s/;(-)?\)/';' . $1 . ')))' . (')' x rand(10)) . ('9' x rand(4))/ego;
		s/:(-)?\(/':' . $1 . '(((' . ('(' x rand(10)) . ('8' x rand(4))/ego;
		s#(^|\s):(-)?/(\s|$)#$1 . ':' . $2 . '///' . ('/' x rand(10)) . ('7' x rand(4)) . $3#ego;
	}

	# Your own substitutions from file

	if ($option_substitutions_permissions =~ /^[01][01]1$/) {
		my $file = "$option{dau_files_root_directory}/$option{dau_files_moron_own_substitutions}";

		unless (-e $file && -r $file) {
			print_err("cannot access $file properly");
			return;
		}
		unless (my $return = do $file) {
			if ($@) {
				print_err("parsing $file failed: $@");
			}
			unless (defined($return)) {
				print_err("'do $file' failed");
			}
		}
	}

	# Substitutions making sense performed on german text.
	# The user can turn them off/on

	if ($option_substitutions_permissions =~ /^1[01][01]$/) {

		# verbs

		s/\b(f)reuen\b/$1roien/gio;
		s/\b(f)reue\b/$1roie/gio;
		s/\b(f)reust\b/$1roist/gio;
		s/\b(f)reut\b/$1roit/gio;

		s/\b(f)unktionieren\b/$1unzen/gio;
		s/\b(f)unktioniere\b/$1unze/gio;
		s/\b(f)unktionierst\b/$1unzt/gio;
		s/\b(f)unktioniert\b/$1unzt/gio;

		s/\b(h)olen\b/$1ohlen/gio;
		s/\b(h)ole\b/$1ohle/gio;
		s/\b(h)olst\b/$1ohlst/gio;
		s/\b(h)olt\b/$1ohlt/gio;

		s/\b(k)onfigurieren\b/$1 eq 'k' ? 'confen' : 'Confen'/egio;
		s/\b(k)onfiguriere\b/$1 eq 'k' ? 'confe' : 'Confe'/egio;
		s/\b(k)onfigurierst\b/$1 eq 'k' ? 'confst' : 'Confst'/egio;
		s/\b(k)onfiguriert\b/$1 eq 'k' ? 'conft' : 'Conft'/egio;

		s/\b(l)achen\b/$1len/gio;
		s/\b(l)ache\b/$1le/gio;
		s/\b(l)achst\b/$1lst/gio;
		s/\b(l)acht\b/$1lt/gio;

		s/\b(m)achen\b/$1 eq 'm' ? 'tun' : 'Tun'/egio;
		s/\b(m)ache\b/$1 eq 'm' ? 'tu' : 'Tu'/egio;
		s/\b(m)achst\b/$1 eq 'm' ? 'tust' : 'Tust'/egio;

		s/\b(n)erven\b/$1erfen/gio;
		s/\b(n)erve\b/$1erfe/gio;
		s/\b(n)ervst\b/$1erfst/gio;
		s/\b(n)ervt\b/$1erft/gio;

		s/\b(p)rojizieren\b/$1rojezieren/gio;
		s/\b(p)rojiziere\b/$1rojeziere/gio;
		s/\b(p)rojizierst\b/$1rojezierst/gio;
		s/\b(p)rojiziert\b/$1rojeziert/gio;

		s/\b(r)egistrieren\b/$1egestrieren/gio;
		s/\b(r)egistriere\b/$1egestriere/gio;
		s/\b(r)egistrierst\b/$1egestrierst/gio;
		s/\b(r)egistriert\b/$1egestriert/gio;

		s/\b(s)pazieren\b/$1patzieren/gio;
		s/\b(s)paziere\b/$1patziere/gio;
		s/\b(s)pazierst\b/$1patzierst/gio;
		s/\b(s)paziert\b/$1patziert/gio;

		# other

		s/\bdanke\b/
		  if (int(rand(2)) == 0) {
		      'thx'
		  } else {
		      'danks'
		  }
		 /ego;
		s/\bDanke\b/
		  if (int(rand(2)) == 0) {
		      'Thx'
		  } else {
		      'Danks'
		  }
		 /ego;

		s/\blol\b/
		  if (int(rand(2)) == 0) {
		      'll'
		  } else {
		      'lllens'
		  }
		 /ego;
		s/\bLOL\b/
		  if (int(rand(2)) == 0) {
		      'LL'
		  } else {
		      'LLLENS'
		  }
		 /ego;

		s/\br(?:|ue)ckgrat\b/
		  if (int(rand(3)) == 0) {
		      'rckgrad'
		  } elsif (int(rand(3)) == 1) {
		      'rckrad'
		  } else {
		      'rckrat'
		  }
		 /ego;
		s/\bR(?:|ue)ckgrat\b/
		  if (int(rand(3)) == 0) {
		      'Rckgrad'
		  } elsif (int(rand(3)) == 1) {
		      'Rckrad'
		  } else {
		      'Rckrat'
		  }
		 /ego;

		s/\b(i)st er\b/$1ssa/gio;
		s/\bist\b/int(rand(2)) ? 'is' : 'iss'/ego;
		s/\bIst\b/int(rand(2)) ? 'Is' : 'Iss'/ego;

		s/\b(d)a(?:ss|) du\b/$1asu/gio;
		s/\b(d)a(?:ss|)\b/$1as/gio;

		s/\b(s)ag mal\b/$1amma/gio;
		s/\b(n)ochmal\b/$1omma/gio;
		s/(m)al\b/$1a/gio;

		s/\b(u)nd nun\b/$1nnu/gio;
		s/\b(n)un\b/$1u/gio;
		s/\b(u)nd\b/$1nt/gio;

		s/\b(s)oll denn\b/$1olln/gio;
		s/\b(d)enn\b/$1en/gio;

		s/\b(s)o eine\b/$1onne/gio;
		s/\b(e)ine\b/$1 eq 'e' ? 'ne' : 'Ne'/egio;

		s/\bkein problem\b/NP/gio;
		s/\b(p)roblem\b/$1rob/gio;
		s/\b(p)robleme\b/$1robs/gio;

		s/\b([[:alpha:]]{2,})st du\b/${1}su/gio;
		s/\b(a)ber\b/$1bba/gio;
		s/\b(a)chso\b/$1xo/gio;
		s/\b(a)dresse\b/$1ddresse/gio;
		s/\b(a)ggressiv\b/$1gressiv/gio;
		s/\b(a)nf(?:|ae)nger\b/$1 eq 'a' ? 'n00b' : 'N00b'/egio;
		s/\b(a)sozial\b/$1ssozial/gio;
		s/\b(a)u(?:ss|)er\b/$1user/gio;
		s/\b(a)utor/$1uthor/gio;
		s/\b(b)(?:ox|(?:|ue)chse)\b/$1yxe/gio;
		s/\b(b)asta\b/$1 eq 'b' ? 'pasta' : 'Pasta'/egio;
		s/\b(b)i(?:ss|)chen\b/$1ischen/gio;
		s/\b(b)illard\b/$1illiard/gio;
		s/\b(b)ist\b/$1is/gio;
		s/\b(b)itte\b/$1 eq 'b' ? 'plz' : 'Plz'/egio;
		s/\b(b)lo(?:ss|)\b/$1los/gio;
		s/\b(b)rillant\b/$1rilliant/gio;
		s/\b(c)hannel\b/$1 eq 'c' ? 'kanal' : 'Kanal'/egio;
		s/\b(c)hat\b/$1hatt/gio;
		s/\b(c)ool\b/$1 eq 'c' ? 'kewl' : 'Kewl'/egio;
		s/\b(d)(?:|ae)mlich\b/$1hmlich/gio;
		s/\b(d)etailliert\b/$1etailiert/gio;
		s/\b(d)ilettantisch\b/$1illetantisch/gio;
		s/\b(d)irekt\b/$1ireckt/gio;
		s/\b(d)iskussion\b/$1isskusion/gio;
		s/\b(d)istribution/$1ystrubution/gio;
		s/\b(e)igentlich\b/$1igendlich/gio;
		s/\b(e)inzige\b/$1inzigste/gio;
		s/\b(e)nd/$1nt/gio;
		s/\b(e)ntschuldigung\b/$1 eq 'e' ? 'sry' : 'Sry'/egio;
		s/\b(f)ilm\b/$1 eq 'f' ? 'movie' : 'Movie'/egio;
		s/\b(f)lachbettscanner\b/$1lachbrettscanner/gio;
		s/\b(f)reu\b/$1roi/gio;
		s/\b(g)alerie\b/$1allerie/gio;
		s/\b(g)ay\b/$1hey/gio;
		s/\b(g)ebaren\b/$1ebahren/gio;
		s/\b(g)elatine\b/$1elantine/gio;
		s/\b(g)eratewohl\b/$1eradewohl/gio;
		s/\b(g)ibt es\b/$1ibbet/gio;
		s/\b(h)(?:|ae)ltst\b/$1lst/gio;
		s/\b(h)(?:|ae)sslich/$1slich/gio;
		s/\b(h)aneb(?:|ue)chen\b/$1ahnebchen/gio;
		s/\b(h)at\b/$1att/gio;
		s/\b(i)mmobilie/$1mobilie/gio;
		s/\b(i)nteressant\b/$1nterressant/gio;
		s/\b(i)ntolerant\b/$1ntollerant/gio;
		s/\b(i)rgend/$1rgent/gio;
		s/\b(j)a\b/$1oh/gio;
		s/\b(j)etzt\b/$1ez/gio;
		s/\b(k)affee\b/$1affe/gio;
		s/\b(k)aputt\b/$1aput/gio;
		s/\b(k)arussell\b/$1arussel/gio;
		s/\b(k)iste\b/$1 eq 'k' ? 'byxe' : 'Byxe'/egio;
		s/\b(k)lempner\b/$1lemptner/gio;
		s/\b(k)r(?:|ae)nker\b/$1ranker/gio;
		s/\b(k)rise\b/$1riese/gio;
		s/\b(l)etal\b/$1ethal/gio;
		s/\b(l)eute\b/$1 eq 'l' ? 'ppl' : 'Ppl'/egio;
		s/\b(l)ibyen\b/$1ybien/gio;
		s/\b(l)izenz\b/$1izens/gio;
		s/\b(l)oser\b/$1ooser/gio;
		s/\b(l)ustig/$1lig/gio;
		s/\b(m)aschine\b/$1aschiene/gio;
		s/\b(m)illennium\b/$1illenium/gio;
		s/\b(m)iserabel\b/$1ieserabel/gio;
		s/\b(m)it dem\b/$1im/gio;
		s/\b(m)orgendlich\b/$1orgentlich/gio;
		s/\b(n)(?:|ae)mlich\b/$1hmlich/gio;
		s/\b(n)ein\b/$1eh/gio;
		s/\b(n)ewbie\b/$100b/gio;
		s/\b(n)iveau/$1iwo/gio;
		s/\b(n)ur\b/$1uhr/gio;
		s/\b(o)riginal\b/$1rginal/gio;
		s/\b(p)aket\b/$1acket/gio;
		s/\b(p)l(?:|oe)tzlich\b/$1lzlich/gio;
		s/\b(p)ogrom\b/$1rogrom/gio;
		s/\b(p)rogramm\b/$1roggie/gio;
		s/\b(p)rogramme\b/$1roggies/gio;
		s/\b(p)sychiater\b/$1sychater/gio;
		s/\b(p)ubert(?:|ae)t\b/$1upertt/gio;
		s/\b(q)uarz\b/$1uartz/gio;
		s/\b(q)uery\b/$1uerry/gio;
		s/\b(r)(o)(t?fl)(o)(l)\b/$1 . ($2 eq 'o' ? '' : '') . $3 . ($4 eq 'o' ? '' : '') . $5/egio;
		s/\b(r)(o)(t?fl)\b/$1 . ($2 eq 'o' ? '' : '') . $3/egio;
		s/\b(r)eparatur\b/$1eperatur/gio;
		s/\b(r)eply\b/$1eplay/gio;
		s/\b(r)essource\b/$1esource/gio;
		s/\b(s)atellit\b/$1attelit/gio;
		s/\b(s)cherz\b/$1chertz/gio;
		s/\b(s)elig\b/$1eelig/gio;
		s/\b(s)eparat\b/$1eperat/gio;
		s/\b(s)eriosit(?:|ae)t\b/$1ersitt/gio;
		s/\b(s)orry\b/$1ry/gio;
		s/\b(s)pelunke\b/$1ilunke/gio;
		s/\b(s)piel\b/$1 eq 's' ? 'game' : 'Game'/egio;
		s/\b(s)tabil\b/$1tabiel/gio;
		s/\b(s)tandard\b/$1tandart/gio;
		s/\b(s)tegreif\b/$1tehgreif/gio;
		s/\b(s)ympathisch\b/$1ymphatisch/gio;
		s/\b(s)yntax\b/$1ynthax/gio;
		s/\b(t)era/$1erra/gio;
		s/\b(t)oler/$1oller/gio;
		s/\b(u)ngef(?:|ae)hr\b/$1ngefr/gio;
		s/\b(v)er(\w+)/$1 eq 'V' ? "Fa$2" : "fa$2"/egio;
		s/\b(v)ielleicht\b/$1ileicht/gio;
		s/\b(v)oraus/$1orraus/gio;
		s/\b(w)(?:|ae)re\b/$1hre/gio;
		s/\b(w)as du\b/$1asu/gio;
		s/\b(w)eil du\b/$1eilu/gio;
		s/\b(w)enn du\b/$1ennu/gio;
		s/\b(w)ider/$1ieder/gio;
		s/\b(w)ieso\b/$1iso/gio;
		s/\b(z)iemlich\b/$1iehmlich/gio;
		s/\b(z)umindest\b/$1umindestens/gio;
		s/\bGra([dt])/$1 eq 'd' ? 'Grat' : 'Grad'/ego;
		s/\bNicht\b/int(rand(2)) ? 'Net' : 'Ned'/ego;
		s/\bSei([dt])\b/$1 eq 'd' ? 'Seit' : 'Seid'/ego;
		s/\bTo([td])/$1 eq 't' ? 'Tod' : 'Tot'/ego;
		s/\bWa(h)?r/$1 eq 'h' ? 'War' : 'Wahr'/ego;
		s/\bWeis(s)?/$1 eq 's' ? 'Weis' : 'Weiss'/ego;
		s/\bgra([dt])/$1 eq 'd' ? 'grat' : 'grad'/ego;
		s/\bnett\b/n1/gio;
		s/\bnicht\b/int(rand(2)) ? 'net' : 'ned'/ego;
		s/\bok(?:ay)?\b/K/gio;
		s/\bsei([dt])\b/$1 eq 'd' ? 'seit' : 'seid'/ego;
		s/\bto([td])/$1 eq 't' ? 'tod' : 'tot'/ego;
		s/\bviel gl(?:|ue)ck\b/GL/gio;
		s/\bwa(h)?r/$1 eq 'h' ? 'war' : 'wahr'/ego;
		s/\bweis(s)?/$1 eq 's' ? 'weis' : 'weiss'/ego;
	}

	if ($option_substitutions_permissions =~ /^[01]1[01]$/) {
		tr//yY/;
		s/ei(?:ss?|)e?/ice/go;
		s/\b([[:alpha:]]+[b-np-tv-z])er\b/${1}a/go;
		s/\b([[:alpha:]]+)ck/${1}q/go;
		s/\b([fv])(?=[[:alpha:]]{2,})/
		  if (rand(10) <= 4) {
		      if ($1 eq 'f') {
		          'v'
		      }
		      else {
		          'f'
		      }
		  } else {
		      $1
		  }
		 /egox;
		s/\b([FV])(?=[[:alpha:]]{2,})/
		  if (rand(10) <= 4) {
		      if ($1 eq 'F') {
		          'V'
		      }
		      else {
		          'F'
		      }
		  } else {
		      $1
		  }
		  /egox;
		s/\b([[:alpha:]]{2,})([td])\b/
		  if (rand(10) <= 4) {
		      if ($2 eq 't') {
		          "$1d"
		      }
		      else {
		          "$1t"
		      }
		  } else {
		      "$1$2"
		  }
		 /egox;
		s/\b([[:alpha:]]{2,})ie/
		  if (rand(10) <= 4) {
		      "$1i"
		  } else {
		      "$1ie"
		  }
		 /egox;
	}

	$data = $_;

	# Swap characters with characters near at the keyboard

	my %mark;
	my %chars = (
	             'a' => [ 's' ],
	             'b' => [ 'v', 'n' ],
	             'c' => [ 'x', 'v' ],
	             'd' => [ 's', 'f' ],
	             'e' => [ 'w', 'r' ],
	             'f' => [ 'd', 'g' ],
	             'g' => [ 'f', 'h' ],
	             'h' => [ 'g', 'j' ],
	             'i' => [ 'u', 'o' ],
	             'j' => [ 'h', 'k' ],
	             'k' => [ 'j', 'l' ],
	             'l' => [ 'k', '' ],
	             'm' => [ 'n' ],
	             'n' => [ 'b', 'm' ],
	             'o' => [ 'i', 'p' ],
	             'p' => [ 'o', '' ],
	             'q' => [ 'w' ],
	             'r' => [ 'e', 't' ],
	             's' => [ 'a', 'd' ],
	             't' => [ 'r', 'z' ],
	             'u' => [ 'z', 'i' ],
	             'v' => [ 'c', 'b' ],
	             'w' => [ 'q', 'e' ],
	             'x' => [ 'y', 'c' ],
	             'y' => [ 'x' ],
	             'z' => [ 't', 'u' ],
	             'A' => [ 'S' ],
	             'B' => [ 'V', 'N' ],
	             'C' => [ 'X', 'V' ],
	             'D' => [ 'S', 'F' ],
	             'E' => [ 'W', 'R' ],
	             'F' => [ 'D', 'G' ],
	             'G' => [ 'F', 'H' ],
	             'H' => [ 'G', 'J' ],
	             'I' => [ 'U', 'O' ],
	             'J' => [ 'H', 'K' ],
	             'K' => [ 'J', 'L' ],
	             'L' => [ 'K', '' ],
	             'M' => [ 'N' ],
	             'N' => [ 'B', 'M' ],
	             'O' => [ 'I', 'P' ],
	             'P' => [ 'O', '' ],
	             'Q' => [ 'W' ],
	             'R' => [ 'E', 'T' ],
	             'S' => [ 'A', 'D' ],
	             'T' => [ 'R', 'Z' ],
	             'U' => [ 'Z', 'I' ],
	             'V' => [ 'C', 'B' ],
	             'W' => [ 'Q', 'E' ],
	             'X' => [ 'Y', 'C' ],
	             'Y' => [ 'X' ],
	             'Z' => [ 'T', 'U' ],
	            );

	# Do not replace one character twice
	# Therefore every replace-position will be marked

	for (0 .. length($data)) {
		$mark{$_} = 0;
	}

	for (0 .. rand(length($data))/20) {
		my $pos = int(rand(length($data)));
		pos $data = $pos;
		unless ($mark{$pos} == 1)  {
			no locale;
			if ($data =~ /\G([A-Za-z])/g) {
				my $replacement = $chars{$1}[int(rand(@{ $chars{$1} }))];
				substr($data, $pos, 1, $replacement);
				$mark{$pos} = 1;
			}
		}
	}

	# plenk

	$data =~ s/(\w+)([,;.:?!]+)(\s+|$)/
	           if (rand(10) <= 8 || $3 eq '') {
	               "$1 $2$3"
	           } else {
	               "$1$2"
	           }
	          /egox;

	# Mix in some typos

	foreach my $word (split /([\s\n])/, $data) {
		if ((rand(100) <= 20) && length($word) > 1) {
			my $random = rand(length($word));
			$random = 2
				if ($random == 1);
			(substr($word, $random, 1), substr($word, $random-1, 1)) =
			(substr($word, $random-1, 1), substr($word, $random, 1));
		}
		$output .= $word;
	}

	# default behaviour: uppercase text

	$output = uc($output) unless (return_option('moron', 'uppercase') eq 'no');

	# do something at EOL

	# 'classic' style

	if ($option_eol_style eq 'classic' ||
	   ($option_eol_style ne 'nothing' && $lastchar eq '!'))
	{
		$output .= ' ';

		my @punct = qw(? !);
		$output .= $punct[rand(@punct)] x int(rand(5))
			for (1..15);

		if ($lastchar eq '?') {
			$output .= '?' x (int(rand(4))+1);
		} elsif ($lastchar eq '!') {
			$output .= '!' x (int(rand(4))+1);
		}

		if ($output =~ /\?$/) {
			$output .= "" x int(rand(10));
		} elsif ($output =~ /!$/) {
			$output .= "1" x int(rand(10));
		}
	}

	# 'new' style

	elsif ($option_eol_style eq 'new') {
		my $random = rand(100);

		# many punctuation marks at EOL

		$output .= ' ';

		if ($random <= 70) {
			my @punct = qw(? !);
			$output .= $punct[rand(@punct)] x int(rand(5))
				for (1..15);

			if ($lastchar eq '?') {
				$output .= '?' x (int(rand(4))+1);
			} elsif ($lastchar eq '!') {
				$output .= '!' x (int(rand(4))+1);
			}

			if ($output =~ /\?$/) {
				$output .= "" x int(rand(10));
			} elsif ($output =~ /!$/) {
				$output .= "1" x int(rand(10));
			}
		}

		# or '??' at EOL

		elsif ($random <= 85) {
			$output .= '??';
		}

		# or "=\n?" at EOL

		else {
			$output .= "=\n?";
		}
	}

	return $output;
}

sub switch_nothing {
	my $data = shift;

	return $data;
}

sub switch_reverse {
	my $data = shift;

	$data = reverse($data);

	return $data;
}

sub switch_stutter {
	my $data = shift;
	my $output;
	my @words = qw(eeeh oeeeh aeeeh);

	foreach (split / (?=\w+\b)/, $data) {
		if (rand(100) < 20) {
			$output .= ' ' . $words[rand(@words)] . ", $_";
		} else {
			$output .= ' ' . $_;
		}
	}

	$output =~ s/\s*,\s+\@/ @/g;

	for (1 .. rand(length($output)/5)) {
		pos $output = rand(length($output));
		$output =~ s/\G ([[:alpha:]]+)\b/ $1, $1/;
	}
	for (1 .. rand(length($output)/10)) {
		pos $output = rand(length($output));
		$output =~ s/\G([[:alpha:]])/$1 . ($1 x rand(3))/e;
	}

	$output =~ s/^\s+//;

	return $output;
}

sub switch_underline {
	my $data = shift;

	$data = "\037$data\037";

	return $data;
}

sub switch_uppercase {
	my $data = shift;

	$data = uc($data);

	return $data;
}

sub switch_words {
	my $data = shift;
	my $output;
	my @numbers;

	if ($option{dau_words_range} =~ /^([1-9])-([1-9])$/) {
		my $x = $1;
		my $y = $2;
		unless ($x <= $y) {
			print_err('Invalid value for setting dau_words_range. ' .
			          "More information: %9${k}dau --help -setting dau_words_range%9");
			return;
		}
		if ($x == $y) {
			push(@numbers, $x);
		} elsif ($x < $y) {
			for (my $i = $x; $i <= $y; $i++) {
				push(@numbers, $i);
			}
		}
	} else {
		print_err('Invalid value for setting dau_words_range. ' .
		          "More information: %9${k}dau --help -setting dau_words_range%9");
		return;
	}
	my $random = $numbers[rand(@numbers)];
	while ($data =~ /((?:.*?(?:\s+|$)){1,$random})/g) {
		$output .= "$1\n"
			unless (length($1) == 0);
		$random = $numbers[rand(@numbers)];
	}

	$output =~ s/\s*$//;

	return $output;
}

################################################################################
# Subroutines (signals)
################################################################################

sub signal_command_msg {
	my ($args, $server, $witem) = @_;

	$args =~ /^(?:-\S+\s)?(?:\S*)\s(.*)/;
	my $data = $1;

	$misc{command_in} .= "$data\n";

	Irssi::signal_stop();
}

sub signal_complete_word {
	my ($list, $window, $word, $linestart, $want_space) = @_;

	# Parsing the commandline for dau.pl is relatively complicated.
	# TAB-Completion depends on commandline parsing in dau.pl.
	# Script autors looking for a simple example for irssi's
	# TAB-Completion are wrong here.

	my $server  = Irssi::active_server();
	my $channel = $window->{active};
	my @switches_combo   = map { $_ = "--$_" } keys %{ $switches{combo} };
	my @switches_nocombo = map { $_ = "--$_" } keys %{ $switches{nocombo} };
	my @nicks;

	# Only complete when the commandline starts with '${k}dau'.
	# If not, let irssi do the work

	return unless ($linestart =~ /^\Q${k}\Edau/i);

	# Remove everything syntactically correct thing of $linestart.
	# If there is anything else but whitespace at the end of
	# commandline parsing, we have an syntax error.
	# If we have a syntax error, complete only nicks.

	$linestart =~ s/^\Q${k}\Edau ?//i;

	# Generate list of nicks in current channel for later use

	if (defined($channel->{type}) && $channel->{type} eq 'CHANNEL') {
		foreach my $nick ($channel->nicks()) {
			if ($nick->{nick} =~ /^\Q$word\E/i &&
			    $window->{active_server}->{nick} ne $nick->{nick})
			{
				push(@nicks, quotemeta($nick->{nick}));
			}
		}
	}

	# Variables

	my $combo = 0;                # Boolean: True if last switch was one of keys %{ $switches{combo} }
	my $syntax_error = 0;         # Boolean: True if syntax error found
	my $counter = 0;              # Integer: Counts First-Level-Options
	my $first_level_option = '';  # String:  Last First-Level-Option
	my $second_level_option = ''; # String:  Last Second-Level-Option
	my $third_level_option = 0;   # Boolean: True if found a Third-Level-Option

	# Parsing commandline now. Set variables accordingly.

	OUTER: while ($linestart =~ /^--(\w+) ?/g) {

		$second_level_option = '';
		$third_level_option  = 0;

		# Found a First-Level-Option (combo)

		if (ref($switches{combo}{$1}{'sub'})) {
			$first_level_option = $1;
			$combo = 1;
		}

		# Found a First-Level-Option (nocombo)

		elsif (ref($switches{nocombo}{$1}{'sub'}) && $counter == 0) {
			$first_level_option = $1;
			$combo = 0;
		}

		# Not a First-Level-Option => Syntax error

		else {
			$syntax_error = 1;
			last OUTER;
		}

		# Syntactically correct => remove it

		$linestart =~ s/^--\w+ ?//;

		# Checkout if there are Second- or Third-Level-Options

		INNER: while ($linestart =~ /^-(\w+)(?: ('[^']+'|\S+))? ?/g) {

			my $second_level = $1;
			my $third_level  = $2 || '';

			$third_level =~ s/^'([^']+)'$/$1/;

			# Do the same for combo and nocombo-options. They have to be
			# handled separately anyway.

			# combo...

			if ($combo) {

				# Found a Second-Level-Option

				if ($switches{combo}{$first_level_option}{$second_level}) {
					$second_level_option = $second_level;
				}

				# Not a Second-Level-Option => Syntax error

				else {
					$syntax_error = 1;
					last OUTER;
				}

				# Syntactically correct => remove it

				$linestart =~ s/^-\w+//;

				# Found something in the regexp of the INNER-while-loop-condition,
				# which is perhaps a Third-Level-Option

				if ($third_level) {

					# Found a Third-Level-Option

					if ($switches{combo}{$first_level_option}{$second_level_option}{$third_level} ||
                                            $switches{combo}{$first_level_option}{$second_level_option}{'*'})
					{
						$third_level_option = 1;

						# Syntactically correct => remove it

						$linestart =~ s/^(?: ('[^']+'|\S+))? ?//;
					}

					# Not a Third-Level-Option => Syntax error

					else {
						$syntax_error = 1;
						last OUTER;
					}

				# Nothing found which comes into question for a Third-Level-Option.
				# The commandline has to be empty now (remember: everything
				# syntactically correct has been removed) or we have a syntax error.

				} else {

					# Empty! Later we will complete to Third-Level-Options

					if ($linestart =~ /^\s*$/) {
						$third_level_option = 0;
					}

					# Not empty => Syntax error

					else {
						$syntax_error = 1;
						last OUTER;
					}
				}

			# nocombo...

			} else {

				# Found a Second-Level-Option

				if ($switches{nocombo}{$first_level_option}{$second_level}) {
					$second_level_option = $second_level;
				}

				# Not a Second-Level-Option => Syntax error

				else {
					$syntax_error = 1;
					last OUTER;
				}

				# Syntactically correct => remove it

				$linestart =~ s/^-\w+//;

				# Found something in the regexp of the INNER-while-loop-condition,
				# which is perhaps a Third-Level-Option

				if ($third_level) {

					# Found a Third-Level-Option

					if ($switches{nocombo}{$first_level_option}{$second_level_option}{$third_level} ||
                                            $switches{nocombo}{$first_level_option}{$second_level_option}{'*'})
					{
						$third_level_option = 1;

						# Syntactically correct => remove it

						$linestart =~ s/^(?: ('[^']+'|\S+))? ?//;
					}

					# Not a Third-Level-Option => Syntax error

					else {
						$syntax_error = 1;
						last OUTER;
					}

				# Nothing found which comes into question for a Third-Level-Option.
				# The commandline has to be empty now (remember: everything
				# syntactically correct has been removed) or we have a syntax error.

				} else {

					# Empty! Later we will complete to Third-Level-Options

					if ($linestart =~ /^\s*$/) {
						$third_level_option = 0;
					}

					# Not empty => Syntax error

					else {
						$syntax_error = 1;
						last OUTER;
					}
				}
			}
		}
	} continue {
		$counter++;
	}

	# End of commandline-parsing.
	# Everything syntactically correct removed.
	# If commandline is not empty now, we have a syntax error.

	if ($linestart !~ /^\s*$/) {
		$syntax_error = 1;
	}

	# Do the TAB-Completion

	if ($syntax_error) {

		foreach my $x (sort @nicks) {
			if($x =~ /^$word/i) {
				push(@$list, $x);
			}
		}
	}

	elsif ($counter == 0) {

		foreach my $x (sort (@switches_combo, @switches_nocombo, @nicks)) {
			if($x =~ /^$word/i) {
				push(@$list, $x);
			}
		}
	}

	elsif (($combo && $first_level_option && $second_level_option && $third_level_option) ||
	       ($combo && $first_level_option && !$second_level_option && !$third_level_option))
	{

		my @switches_second_level = grep !/^-sub$/, map { $_ = "-$_" }
					    keys %{ $switches{combo}{$first_level_option} };

		foreach my $x (sort (@switches_second_level, @switches_combo, @nicks)) {
			if($x =~ /^$word/i) {
				push(@$list, $x);
			}
		}
	}

	elsif ((!$combo && $counter == 1 && $first_level_option && $second_level_option && $third_level_option) ||
	       (!$combo && $counter == 1 && $first_level_option && !$second_level_option && !$third_level_option))
	{
		my @switches_second_level = grep !/^-sub$/, map { $_ = "-$_" }
					    keys %{ $switches{nocombo}{$first_level_option} };

		foreach my $x (sort (@switches_second_level)) {
			if($x =~ /^$word/i) {
				push(@$list, $x);
			}
		}
	}

	elsif ($combo && $first_level_option && $second_level_option && !$third_level_option) {
		my @switches_third_level = grep !/^\*$/,
					   keys %{ $switches{combo}{$first_level_option}{$second_level_option} };

		foreach my $x (sort (@switches_third_level)) {
			if($x =~ /^$word/i) {
				push(@$list, $x);
			}
		}
	}

	elsif (!$combo && $counter == 1 && $first_level_option && $second_level_option && !$third_level_option) {
		my @switches_third_level = grep !/^\*$/,
					   keys %{ $switches{nocombo}{$first_level_option}{$second_level_option} };

		foreach my $x (sort (@switches_third_level)) {
			if($x =~ /^$word/i) {
				push(@$list, $x);
			}
		}
	}

	Irssi::signal_stop();
}

sub signal_event_privmsg {
	my ($server, $data, $nick, $hostmask) = @_;
	my ($channel_name, $text) = split / :/, $data, 2;
	my $channel_rec = $server->channel_find($channel_name);
	$channel_name   = lc($channel_name);
	my $server_name = lc($server->{tag});
	my $own_nick = $server->{nick};
	my %lookup;

	while ($option{dau_remote_channellist} =~ /\s*([^\/]+)\/([^,]+)\s*,?/g) {
		my $channel = $1;
		$channel    = lc($channel);
		my $ircnet  = $2;
		$ircnet     = lc($ircnet);
		$lookup{$ircnet}{$channel} = 1;
	}
	if (lc($option{dau_remote_channelpolicy}) eq 'allow') {
		return if ($lookup{$server_name}{$channel_name});
	} elsif (lc($option{dau_remote_channelpolicy}) eq 'deny') {
		return unless ($lookup{$server_name}{$channel_name});
	} else {
		return;
	}

	# Remove formatting so dau.pl can reply to a colored, underlined, ...
	# 'hallo wie geht'

	$text =~ s/\003\d?\d?(?:,\d?\d?)?|\002|\006|\007|\016|\01f|\037//g;

	if ($text =~ /^ ?hallo wie geht(?:\s*@\s*$own_nick)?[\s?!1]*$/i) {
		my $reply = parse_setting_list('dau_remote_question_reply');
		$reply =~ s/(?<![\\])\$nick/$nick/g;
		$reply = parse_text($reply, $channel_rec);

		output_text($server, $channel_name, $reply);
	}
}

sub signal_nick_mode_changed {
	my ($channel, $nick, $setby, $mode, $type) = @_;
	my ($reply, %lookup);
	my $channel_name = lc($channel->{name});
	my $network_name  = lc($channel->{server}->{tag});
	my $op = $misc{nick_mode}{$network_name}{$channel_name}{op};       # mode before nick change
	my $voice = $misc{nick_mode}{$network_name}{$channel_name}{voice}; # mode before nick change

	return if ($channel->{server}->{nick} ne $nick->{nick});
	if ($nick->{nick} eq $setby || $setby eq 'irc.psychoid.net') {
		build_nick_mode_struct();
		return;
	}

	# Only act in channels where the user wants dau.pl to act

	while ($option{dau_remote_channellist} =~ /\s*([^\/]+)\/([^,]+)\s*,?/g) {
		my $channel = $1;
		$channel    = lc($channel);
		my $ircnet  = $2;
		$ircnet     = lc($ircnet);
		$lookup{$ircnet}{$channel} = 1;
	}
	if (lc($option{dau_remote_channelpolicy}) eq 'allow') {
		if ($lookup{$network_name}{$channel_name}) {
			build_nick_mode_struct();
			return;
		}
	} elsif (lc($option{dau_remote_channelpolicy}) eq 'deny') {
		unless ($lookup{$network_name}{$channel_name}) {
			build_nick_mode_struct();
			return;
		}
	} else {
		build_nick_mode_struct();
		return;
	}

	# Now we are in the right channel

	if ($option{dau_remote_permissions} =~ /^[01]1[01][01][01][01]$/) {
		if ($mode eq '+' && $type eq '+' && (!$voice && !$op)) {
			$reply = parse_setting_list('dau_remote_voice_reply');
			$reply =~ s/(?<![\\])\$nick/$setby/g;
			$reply = parse_text($reply, $channel);
		}
	}
	if ($option{dau_remote_permissions} =~ /^[01][01]1[01][01][01]$/) {
		if ($mode eq '@' && $type eq '+' && !$op) {
			$reply = parse_setting_list('dau_remote_op_reply');
			$reply =~ s/(?<![\\])\$nick/$setby/g;
			$reply = parse_text($reply, $channel);
		}
	}
	if ($option{dau_remote_permissions} =~ /^[01][01][01]1[01][01]$/) {
		if ($mode eq '+' && $type eq '-' && ($voice && !$op)) {
			$reply = parse_setting_list('dau_remote_devoice_reply');
			$reply =~ s/(?<![\\])\$nick/$setby/g;
			$reply = parse_text($reply, $channel);
		}
	}
	if ($option{dau_remote_permissions} =~ /^[01][01][01][01]1[01]$/) {
		if ($mode eq '@' && $type eq '-' && $op) {
			$reply = parse_setting_list('dau_remote_deop_reply');
			$reply =~ s/(?<![\\])\$nick/$setby/g;
			$reply = parse_text($reply, $channel);
		}
	}

	# rebuild nick mode struct and print out the reply

	build_nick_mode_struct();
	output_text($channel, $channel->{name}, $reply);
}

sub signal_send_text {
	my ($data, $server, $witem) = @_;
	my $output;

	return unless (defined($server) && $server && $server->{connected});
	return unless (defined($witem) && $witem &&
	              ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY'));

	if ($misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} == 1) {
		if ($misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} eq '') {
			$output = parse_text($misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} . $data, $witem);
		} else {
			$output = parse_text($misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} . ' ' . $data, $witem);
		}

		output_text($witem, $witem->{name}, $output);

		Irssi::signal_stop();
	}
}

sub signal_setup_changed {
	set_settings();

	# setting changed/added => change/add it here

	# setting cmdchars

	$k = Irssi::parse_special('$k');

	# setting dau_cowsay_cowpath

	cowsay_cowlist($option{dau_cowsay_cowpath});

	# setting dau_figlet_fontpath

	figlet_fontlist($option{dau_figlet_fontpath});

	# setting dau_statusbar_daumode_hide_when_off

	Irssi::statusbar_items_redraw('daumode');

	# timer for the babble-feature

	timer_babble_reset();

	# signal handling

	signal_handling();
}

sub signals_idaumode {
	my ($server, $data, $nick, $hostmask, $target) = @_;
	my $channel_rec = $server->channel_find($target);
	my $i_channel = $misc{daumode_ichannels}{$server->{tag}}{$target};
	my $i_modes   = $misc{daumode_ichannels_modes}{$server->{tag}}{$target};
	my $modified_msg;

	return unless (defined($server) && $server && $server->{connected});

	# Not one of the channels where daumode for incoming messages is turned on.
	# In those channels print out the message as it is and leave the subroutine

	if (!$i_channel) {
		return;
	}

	# Evil Hack...
	# I had to dauify every incoming messages. Using &signal_continue was
	# not possible because --words f.e. generates multilineoutput. So i had
	# to create multiple messages using &signal_emit. Those just created
	# messages shouldn't be dauified again when entering this subroutine. I
	# couldn't prevent irssi from entering this subroutine again after
	# dauifying the text so the messages had to be 'marked'. Marked messages
	# will not be dauified again. I think \x02 at the beginning of the
	# message is ok for that... I know this whole crap here can be done
	# MUCH MORE elegant. I do not have more time for that. Send me a patch
	# if you want a change here.

	if ($data =~ s/^\x02//) {
		Irssi::signal_continue($server, $data, $nick, $hostmask, $target);
	} else {
		if ($i_modes ne '') {
			$modified_msg = parse_text($i_modes . ' ' . $data, $channel_rec);
		} else {
			$modified_msg = parse_text($data, $channel_rec);
		}

		if ($modified_msg =~ /\n/) {
			for my $line (split /\n/, $modified_msg) {
				Irssi::signal_emit(Irssi::signal_get_emitted(), $server, "\x02$line", $nick, $hostmask, $target);
				Irssi::signal_stop();
			}
		} else {
			Irssi::signal_emit(Irssi::signal_get_emitted(), $server, "\x02$modified_msg", $nick, $hostmask, $target);
			Irssi::signal_stop();
		}
	}
}

################################################################################
# Subroutines (statusbar)
################################################################################

sub statusbar_daumode {
	my ($item, $get_size_only) = @_;
	my ($i_status, $o_status, $i_modes, $o_modes);
	my $server = Irssi::active_server();
	my $witem  = Irssi::active_win()->{active};
	my $theme  = Irssi::current_theme();
	my $format = $theme->format_expand('{sb_daumode}');

	if ($witem && ref($witem) &&
	    $server && ref($server) &&
	   ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY'))
	{
		if (defined($misc{daumode_ichannels}{$server->{tag}}{$witem->{name}}) &&
		    $misc{daumode_ichannels}{$server->{tag}}{$witem->{name}} == 1)
		{
			$i_status = 'ON';
		} else {
			$i_status = 'OFF';
		}

		if (defined($misc{daumode_ochannels}{$server->{tag}}{$witem->{name}}) &&
		    $misc{daumode_ochannels}{$server->{tag}}{$witem->{name}} == 1)
		{
			$o_status = 'ON';
		} else {
			$o_status = 'OFF';
		}

		# Hide statusbaritem if setting dau_statusbar_daumode_hide_when_off
		# is turned on and daumode is turned off

		if ($i_status eq 'OFF' && $o_status eq 'OFF' && $option{dau_statusbar_daumode_hide_when_off}) {
			$item->{min_size} = $item->{max_size} = 0;
			return;
		}

		if ($i_status eq 'ON') {
			$i_modes = $misc{daumode_ichannels_modes}{$server->{tag}}{$witem->{name}} || $option{dau_standard_options};
		} else {
			$i_modes = '';
		}
		if ($o_status eq 'ON') {
			$o_modes = $misc{daumode_ochannels_modes}{$server->{tag}}{$witem->{name}} || $option{dau_standard_options};
		} else {
			$o_modes = '';
		}

		if ($format) {
			$format = $theme->format_expand("{sb_daumode $o_status $o_modes $i_status $i_modes}");
		} else {
			if ($i_status eq 'OFF' && $o_status eq 'OFF') {
				$format = $theme->format_expand("{sb daumode: <- $i_status | -> $o_status}");
			}
			elsif ($i_status eq 'OFF' && $o_status eq 'ON') {
				$format = $theme->format_expand("{sb daumode: <- $i_status | -> $o_status ($o_modes)}");
			}
			elsif ($i_status eq 'ON' && $o_status eq 'OFF') {
				$format = $theme->format_expand("{sb daumode: <- $i_status ($i_modes) | -> $o_status}");
			}
			elsif ($i_status eq 'ON' && $o_status eq 'ON') {
				$format = $theme->format_expand("{sb daumode: <- $i_status ($i_modes) | -> $o_status ($o_modes)}");
			}
		}
	} else {
		$item->{min_size} = $item->{max_size} = 0;
		return;
	}

	$item->default_handler($get_size_only, $format, '', 1);
}

################################################################################
# Subroutines (timer)
################################################################################

# for the babble remote feature

sub timer_babble {
	my $text;

	# Push all channels where it's ok to babble text in @channels

	my %lookup;
	while ($option{dau_remote_babble_channellist} =~ /\s*([^\/]+)\/([^,]+)\s*,?/g) {
		my $channel = $1;
		$channel    = lc($channel);
		my $ircnet  = $2;
		$ircnet     = lc($ircnet);
		$lookup{$ircnet}{$channel} = 1;
	}

	my @channels;
	foreach my $server (Irssi::servers()) {
		my $server_name = lc($server->{tag});

		foreach my $channel ($server->channels()) {
			my $channel_name = lc($channel->{name});

			if (lc($option{dau_remote_babble_channelpolicy}) eq 'allow' &&
			    !$lookup{$server_name}{$channel_name})
			{
				push(@channels, $channel);
			}
			elsif (lc($option{dau_remote_babble_channelpolicy}) eq 'deny' &&
			       $lookup{$server_name}{$channel_name})
			{
				push(@channels, $channel);
			}
		}
	}

	# No channels found => return

	return if (@channels == 0);

	# Choose one of the @channels

	my $channel = $channels[rand(@channels)];

	# If --babble is babbling now exit

	if (defined($misc{switch_babble_timer_writing})) {
		return;
	}

	# else get text from file

	else {
		$text = &babble_get_text($channel);
	}

	# We have two timers in the game:
	#
	# timer_babble() and timer_babble_reset() managing the big breaks between
	# the babbling
	#
	# timer_babble_writing() and timer_babble_writing_reset() managing the
	# breaks between the lines of one babbling (simulating a user typing).

	# These are some global variables for the writing timer

	$misc{timer_babble_writing}{channelname}    = $channel->{name};
	$misc{timer_babble_writing}{channel}        = $channel;
	$misc{timer_babble_writing}{counter}        = 0;
	$misc{timer_babble_writing}{text}           = "$text\n";
	$misc{timer_babble_writing}{numberoflines}  = 0;
	$misc{timer_babble_writing}{numberoflines}++ while ($misc{timer_babble_writing}{text} =~ /\n/g);
	$misc{timer_babble_writing}{numberoflines} -= 1;

	# First stop the big breaks timer then start the writing timer. It will
	# write down the dauified text with breaks between the lines simulating a user
	# typing. When it's done it will restart the babble timer for the big breaks.

	Irssi::timeout_remove($misc{remote_babble_timer}) if (defined($misc{remote_babble_timer}));
	timer_babble_writing_reset();
}

# for the babble remote feature

sub timer_babble_reset {
	Irssi::timeout_remove($misc{remote_babble_timer}) if (defined($misc{remote_babble_timer}));

	# Do not set the timer, if the permission-bit is not set

	return unless ($option{dau_remote_permissions} =~ /^[01][01][01][01][01]1$/);

	# Calculate interval

	my $interval = $option{dau_remote_babble_interval} * 1000;

	my $addend;
	if ($option{dau_remote_babble_interval_accuracy} == 100) {
		$addend = 0;
	} elsif ($option{dau_remote_babble_interval_accuracy} > 0 &&
	         $option{dau_remote_babble_interval_accuracy} < 100)
	{
		$addend = rand($interval - ($interval * ($option{dau_remote_babble_interval_accuracy} / 100)));
	} else {
		print_err('Invalid value of dau_remote_babble_interval_accuracy');
		return;
	}

	if (int(rand(2))) {
		$interval = $interval + $addend;
	} else {
		$interval = $interval - $addend;
	}

	$interval = int($interval);

	if ($interval < 10 || $interval > 1000000000) {
		print_err('Invalid value of dau_remote_babble_interval');
		return;
	}

	# Set timer

	$misc{remote_babble_timer} = Irssi::timeout_add($interval, \&timer_babble, '');
}

# for the babble remote feature: the writing

sub timer_babble_writing {
	# Print the current line unless --babble is writing now

	unless (defined($misc{switch_babble_timer_writing})) {

		# restore the variables

		$misc{command_out} = $misc{babble_command_out_history}{$misc{timer_babble_writing}{counter}};
		$misc{switch_command_out} = $misc{babble_switch_command_out_history}{$misc{timer_babble_writing}{counter}};

		# then output text

		output_text($misc{timer_babble_writing}{channel}, $misc{timer_babble_writing}{channelname}, $misc{timer_babble_writing}{line});
	}

	# And go to the "managing" subroutine...

	timer_babble_writing_reset();
}

# for the babble remote feature: the writing

sub timer_babble_writing_reset {
	# Remove used writing timer, if existent (at the first run we don't have any timer)

	Irssi::timeout_remove($misc{remote_babble_timer_writing}) if (defined($misc{remote_babble_timer_writing}));

	# At each run of this managing subroutine remove one line of text

	$misc{timer_babble_writing}{text} =~ s/^(.*?)\n//;
	$misc{timer_babble_writing}{line} = $1;

	# If there is still some text left, add a new timer for the next line

	if (length($misc{timer_babble_writing}{text}) != 0 || length($misc{timer_babble_writing}{line}) != 0) {
		# First run: Call timer_babble_writing() directly to avoid a break

		if ($misc{timer_babble_writing}{counter}++ == 0) {
			if ($option{dau_babble_verbose} &&
			    $misc{timer_babble_writing}{numberoflines} >= $option{dau_babble_verbose_minimum_lines})
			{
				$misc{timer_babble_writing}{channel}->print("%9dau.pl:%9 Babbling $misc{timer_babble_writing}{numberoflines} line" . ($misc{timer_babble_writing}{numberoflines} > 1 ? 's' : '') . ' now:');
			}
			timer_babble_writing();
		}

		# Not the first run? Normal behaviour and the timer for the breaks

		else {
			# Calculate the writing breaks
			# The longer the next line is the longer the break will be

			my $interval = 1000 + rand(2000) +
			               50 * length($misc{timer_babble_writing}{line}) +
			               rand(25 * length($misc{timer_babble_writing}{line}));

			# Some characters need more time to write

			while ($misc{timer_babble_writing}{line} =~ /[^a-z ]/gio) {
				$interval += (75 + rand(25));
			}

			$interval = int($interval);

			# Set timer

			$misc{remote_babble_timer_writing} = Irssi::timeout_add($interval, \&timer_babble_writing, '');
		}
	}

	# Nothing left?
	# Go to the managing subroutine for the "big breaks timer" (restart)

	else {

		# print the verbose info if setting is set

		if ($option{dau_babble_verbose} &&
		    $misc{timer_babble_writing}{numberoflines} >= $option{dau_babble_verbose_minimum_lines})
		{
			$misc{timer_babble_writing}{channel}->print('%9dau.pl:%9 Finished babbling.');
		}

		# remove the timer

		undef($misc{remote_babble_timer_writing});
		timer_babble_reset();
	}
}

# for --babble: the writing

sub timer_switch_babble_writing {
	# Print the current line unless the remote babble feature is writing now

	unless (defined($misc{remote_babble_timer_writing})) {

		# restore the variables

		$misc{command_out} = $misc{babble_command_out_history}{$misc{timer_switch_babble_writing}{counter}};
		$misc{switch_command_out} = $misc{babble_switch_command_out_history}{$misc{timer_switch_babble_writing}{counter}};

		# then output text

		output_text($misc{timer_switch_babble_writing}{channel}, $misc{timer_switch_babble_writing}{channelname}, $misc{timer_switch_babble_writing}{line});
	}

	# And go to the "managing" subroutine...

	timer_switch_babble_writing_reset();
}

# for --babble: the writing

sub timer_switch_babble_writing_reset {
	# Remove used writing timer, if existent (at the first run we don't have any timer)

	Irssi::timeout_remove($misc{switch_babble_timer_writing}) if (defined($misc{switch_babble_timer_writing}));

	# At each run of this managing subroutine remove one line of text

	$misc{timer_switch_babble_writing}{text} =~ s/^(.*?)\n//;
	$misc{timer_switch_babble_writing}{line} = $1;

	# If there is still some text left, add a new timer for the next line

	if (length($misc{timer_switch_babble_writing}{text}) != 0 || length($misc{timer_switch_babble_writing}{line}) != 0) {
		# First run: Call timer_babble_writing() directly to avoid a break

		if ($misc{timer_switch_babble_writing}{counter}++ == 0) {
			if ($option{dau_babble_verbose} && $misc{timer_switch_babble_writing}{numberoflines} >= $option{dau_babble_verbose_minimum_lines}) {
				$misc{timer_switch_babble_writing}{channel}->print("%9dau.pl:%9 Babbling $misc{timer_switch_babble_writing}{numberoflines} line" . ($misc{timer_switch_babble_writing}{numberoflines} > 1 ? 's' : '') . ' now:');
			}
			timer_switch_babble_writing();
		}

		# Not the first run? Normal behaviour and the timer for the breaks

		else {
			# Calculate the writing breaks
			# The longer the next line is the longer the break will be

			my $interval = 1000 + rand(2000) +
			               50 * length($misc{timer_switch_babble_writing}{line}) +
			               rand(25 * length($misc{timer_switch_babble_writing}{line}));

			# Some characters need more time to write

			while ($misc{timer_switch_babble_writing}{line} =~ /[^a-z ]/gio) {
				$interval += (75 + rand(25));
			}

			$interval = int($interval);

			# Set timer

			$misc{switch_babble_timer_writing} = Irssi::timeout_add($interval, \&timer_switch_babble_writing, '');
		}
	}

	# No text left?

	else {
		if ($option{dau_babble_verbose} && $misc{timer_switch_babble_writing}{numberoflines} >= $option{dau_babble_verbose_minimum_lines}) {
			$misc{timer_switch_babble_writing}{channel}->print('%9dau.pl:%9 Finished babbling.');
		}

		# remove the timer

		undef($misc{switch_babble_timer_writing});
	}
}

################################################################################
# Helper subroutines
################################################################################

sub babble_get_text {
	my ($channel) = @_;
	my $output;

	# Return a random line from the dau_files_babble_messages file

	my $text;
	my $file = "$option{dau_files_root_directory}/$option{dau_files_babble_messages}";
	$/ = "\n";
	@ARGV = ($file);
	srand;
	rand($.) < 1 && ($text = $_) while <>;

	# Build nick array with every nick in channel and
	# opnick array with every op in the channel

	my @nicks = ();
	my @opnicks = ();
	if (defined($channel) && $channel && $channel->{type} eq 'CHANNEL') {
		foreach my $nick ($channel->nicks()) {
			next if ($channel->{server}->{nick} eq $nick->{nick});
			push(@nicks, $nick->{nick});
			push(@opnicks, $nick->{nick}) if ($nick->{op});
		}
	}

	# Substitution: \n to a real newline

	$text =~ s/\\n/\n/g;

	# Substitution: $rnick to a random nick of $channel

	my $rnick;
	if (@nicks == 0) {
		$rnick = 'foo';
	} else {
		$rnick = $nicks[rand(@nicks)];
	}

	$text =~ s/(?<![\\])\$rnick/$rnick/g;

	# Substitution: $nick1..$nickn

	while ($text =~ /\$nick(\d+)/g) {
		my $substitution = $nicks[rand(@nicks)];
		$text =~ s/(?<![\\])\$nick$1([^\d]|$)/${substitution}$1/g;
		@nicks = grep { $_ ne $substitution } @nicks;
		last if (@nicks == 0);
	}

	# Substitution: $opnick1..$opnickn

	while ($text =~ /\$opnick(\d+)/g) {
		my $substitution = $opnicks[rand(@opnicks)];
		$text =~ s/(?<![\\])\$opnick$1([^\d]|$)/${substitution}$1/g;
		@opnicks = grep { $_ ne $substitution } @opnicks;
		last if (@opnicks == 0);
	}

	# Substitution: $?{ code }

	my $np; # (nested pattern)
	$np = qr{
		  {
	          (?:
	             (?> [^{}]+ ) # Non-capture group w/o backtracking
	           |
	             (??{ $np })  # Group with matching parens
	          )*
		  }
	        }x;

	while ($text =~ /\$\?($np)/g) {
		{
			no strict;
			my $replacement = eval $1;
			if ($@) {
				print_err('Invalid code used in babble message construct $?{ code }. Details:');
				print_err($@);
				return;
			} else {
				chomp($replacement);
				$text =~ s/\$\?($np)/$replacement/;
			}
		}
	}

	# Substitution: irssi's special variables

	if ((defined($channel) && $channel &&
	    ($channel->{type} eq 'CHANNEL' || $channel->{type} eq 'QUERY')))
	{
		$text = $channel->parse_special($text);
	}

	# dauify $text and return the dauified $output

	my $options = $option{dau_babble_standard_options};

	# We have to keep track of the command history. --me and the --command
	# switch change the variables $misc{command_out} and $misc{switch_command_out}.
	# Because they are reset after every run of parse_text() they have to be kept
	# in a struct so that the writing timers later can do their job correctly.

	my $counter = 1;
	$misc{babble_command_out_history} = ();
	$misc{babble_switch_command_out_history} = ();

	# Process $text line by line

	$text =~ s/\n$//;
	while ($text =~ /(.*?)(\n|$)/g) {

		# Exit while loop when finished

		last if ($2 ne "\n" && $1 eq "");

		# Dauify text

		my $newtext = parse_text("$options $1") . "\n";
		$output .= $newtext;

		# The parsed text ($newtext) can contain more than one line.
		# All $newtext lines have the same command.
		# The command (MSG, ACTION, ...) has to be remembered.

		while ($newtext =~ /\n/g) {
			$misc{babble_command_out_history}{$counter} = $misc{command_out};
			$misc{babble_switch_command_out_history}{$counter} = $misc{switch_command_out};
			$counter++;
		}
	}

	# Lines are separated by newline characters. Maybe there are to many of
	# them at the end of the string (probably produced by --figlet, --cowsay, ...).
	# That's disturbing the number of lines calculation later.

	$output =~ s/\n{2,}$/\n/;

	# $output contains now the text to be babbled.  It will be split by
	# newlines by the babble subroutines and each line will be babbled with
	# the correct commands restored.

	return $output;
}

sub build_nick_mode_struct {
	undef($misc{nick_mode});

	foreach my $server (Irssi::servers()) {
		my $network_name = lc($server->{tag});

		foreach my $channel ($server->channels()) {
			my $channel_name = lc($channel->{name});
			my $op = $channel->{ownnick}{op};
			my $voice = $channel->{ownnick}{voice};

			$misc{nick_mode}{$network_name}{$channel_name}{op} = $op;
			$misc{nick_mode}{$network_name}{$channel_name}{voice} = $voice;
		}
	}
}

sub def_dau_cowsay_cowpath {
	my $cowsay = $ENV{COWPATH} || '/usr/share/cowsay/cows';
	chomp($cowsay);
	return $cowsay;
}

sub def_dau_cowsay_cowsay_path {
	my $cowsay = `which cowsay`;
	chomp($cowsay);
	return $cowsay;
}

sub def_dau_cowsay_cowthink_path {
	my $cowthink = `which cowthink`;
	chomp($cowthink);
	return $cowthink;
}

sub def_dau_figlet_fontpath {
	my $figlet = `figlet -I2`;
	chomp($figlet);
	return $figlet;
}

sub def_dau_figlet_path {
	my $figlet = `which figlet`;
	chomp($figlet);
	return $figlet;
}

sub cowsay_cowlist {
	my $cowsay_cowpath = shift;

	# clear cowlist

	%{ $switches{combo}{cowsay}{cow} } = ();

	# generate new list

	while (<$cowsay_cowpath/*.cow>) {
		my $cow = (fileparse($_, qr/\.[^.]*/))[0];
		$switches{combo}{cowsay}{cow}{$cow} = 1;
	}
}

sub figlet_fontlist {
	my $figlet_fontpath = shift;

	# clear fontlist

	%{ $switches{combo}{figlet}{font} } = ();

	# generate new list

	while (<$figlet_fontpath/*.flf>) {
		my $font = (fileparse($_, qr/\..*/))[0];
		$switches{combo}{figlet}{font}{$font} = 1;
	}
}

sub fix {
	my $string = shift;
	$string =~ s/^\t+//gm;
	return $string;
}

sub output_text {
	my ($thing, $target, $text) = @_;

	foreach my $line (split /\n/, $text) {

		# --command -out <command>?

		if ($misc{switch_command_out}) {
			if (defined($thing) && $thing) {
				$thing->command("$misc{command_out} $line");
			} else {
				my $server = Irssi::active_server();

				if (defined($server) && $server && $server->{connected}) {
					$server->command("$misc{command_out} $line");
				} else {
					print CLIENTCRAP $line;
				}
			}
		}

		# Not a channel/query-window, --help, --changelog, ...

		elsif ($misc{'print'}) {
			print CLIENTCRAP $line;
		}

		# Normal behaviour

		elsif ($misc{command_out} eq 'ACTION' || $misc{command_out} eq 'MSG') {
			$thing->command("$misc{command_out} $target $line");
		}

		# if weird things happened...

		else {
			print CLIENTCRAP $line;
		}
	}
}

sub parse_setting_list {
	my $arg = shift;
	my @strings;

	while ($option{$arg} =~ /\s*([^,]+)\s*,?/g) {
		push @strings, $1;
	}

	if (@strings == 0) {
		return;
	} else {
		return $strings[rand(@strings)];
	}
}

sub parse_text {
	my ($data, $channel_rec) = @_;
	my $output;

	%{ $misc{queue} }         = ();
	$misc{'print'}            = 0;
	$misc{command_out}        = 'MSG';
	$misc{counter}            = 0;
	$misc{daumode}            = 0;
	$misc{switch_command_out} = 0;

	OUTER: while ($data =~ /^--(\w+) ?/g) {

		my $first_level_option  = $1;

		# If its the first time we are in the OUTER loop, check
		# if the First-Level-Option is one of the few options,
		# which must not be combined.

		if (ref($switches{nocombo}{$first_level_option}{'sub'}) && $misc{counter} == 0) {

			$data =~ s/^--\w+ ?//;

			# found a First-Level-Option

			$misc{queue}{$misc{counter}}{$first_level_option} = { };

			# Check for Second-Level-Options and Third-Level-Options.
			# Get all of them and put theme in the
			# $misc{queue} hash

			while ($data =~ /^-(\w+) ('[^']+'|\S+) ?/g) {

				my $second_level_option = $1;
				my $third_level_option  = $2;

				$third_level_option =~ s/^'([^']+)'$/$1/;

				# If $switches{nocombo}{$first_level_option}{$second_level_option}{'*'}:
				# The user can give any third_level_option on the commandline

				my $any_option =
				$switches{nocombo}{$first_level_option}{$second_level_option}{'*'} ? 1 : 0;

				if ($switches{nocombo}{$first_level_option}{$second_level_option}{$third_level_option} ||
				    $any_option)
				{
					$misc{queue}{$misc{counter}}{$first_level_option}{$second_level_option} = $third_level_option;
				}

				$data =~ s/^-(\w+) ('[^']+'|\S+) ?//;
			}

			# initialize some values

			foreach my $second_level_option (keys(%{ $switches{nocombo}{$first_level_option} })) {
				if (!defined($misc{queue}{'0'}{$first_level_option}{$second_level_option})) {
					$misc{queue}{'0'}{$first_level_option}{$second_level_option} = '';
				}
			}

			# All done. Run the subroutine

			$output = &{ $switches{nocombo}{$first_level_option}{'sub'} }($data, $channel_rec);

			return $output;
		}

		# Check for all those options that can be combined.

		elsif (ref($switches{combo}{$first_level_option}{'sub'})) {

			$data =~ s/^--\w+ ?//;

			# found a First-Level-Option

			$misc{queue}{$misc{counter}}{$first_level_option} = { };

			# Check for Second-Level-Options and
			# Third-Level-Options. Get all of them and put them
			# in the $misc{queue} hash

			while ($data =~ /^-(\w+) ('[^']+'|\S+) ?/g) {

				my $second_level_option = $1;
				my $third_level_option  = $2;

				$third_level_option =~ s/^'([^']+)'$/$1/;

				# If $switches{combo}{$first_level_option}{$second_level_option}{'*'}:
				# The user can give any third_level_option on the commandline

				my $any_option =
				$switches{combo}{$first_level_option}{$second_level_option}{'*'} ? 1 : 0;

				# known option => Put it in the hash

				if ($switches{combo}{$first_level_option}{$second_level_option}{$third_level_option}
			            || $any_option)
				{
					$misc{queue}{$misc{counter}}{$first_level_option}{$second_level_option} = $third_level_option;
					$data =~ s/^-(\w+) ('[^']+'|\S+) ?//;
				} else {
					last OUTER;
				}
			}

			# increase counter

			$misc{counter}++;
		}

		else {
			last OUTER;
		}
	}

	# initialize some values

	for (my $i = 0; $i < $misc{counter}; $i++) {
		foreach my $first_level (keys(%{ $misc{queue}{$i} })) {
			if (ref($switches{combo}{$first_level})) {
				foreach my $second_level (keys(%{ $switches{combo}{$first_level} })) {
					if (!defined($misc{queue}{$i}{$first_level}{$second_level})) {
						$misc{queue}{$i}{$first_level}{$second_level} = '';
					}
				}
			}
		}
	}

	# text to subroutines

	$output = $data;

	# If theres no text left over, take one item of dau_random_messages

	if ($output =~ /^\s*$/) {
		$output = parse_setting_list('dau_standard_messages');
	}

	# No options? Get options from setting dau_standard_options and run
	# parse_text() again

	if (keys %{ $misc{queue} } == 0) {

		if (!$misc{subcounter}) {
			$misc{subcounter}++;
			$output = parse_text("$option{dau_standard_options} $output", $channel_rec);
		} else {
			print_err('Invalid value for setting dau_standard_options. ' .
			          'Will use %9--moron%9 instead!');
			$output =~ s/^\Q$option{dau_standard_options}\E //;
			$output = parse_text("--moron $output", $channel_rec);
		}

	} else {

		$misc{counter} = 0;

		for (keys(%{ $misc{queue} })) {
			my ($first_level_option) = keys %{ $misc{queue}{$misc{counter}} };
			$output = &{ $switches{combo}{$first_level_option}{'sub'} }($output, $channel_rec);
			$misc{counter}++;
		}
	}

	# reset subcounter

	$misc{subcounter} = 0;

	# return text

	return $output;
}

sub print_err {
	my $text = shift;

	foreach my $line (split /\n/, $text) {
		print CLIENTCRAP "%Rdau.pl error%n: $line";
	}
}

sub print_out {
	my $text = shift;

	foreach my $line (split /\n/, $text) {
		print CLIENTCRAP "%9dau.pl%9: $line";
	}
}

sub return_option {
	if (@_ == 2) {
		return $misc{queue}{$misc{counter}}{$_[0]}{$_[1]};
	} elsif (@_ == 3) {
		if ($misc{queue}{$misc{counter}}{$_[0]}{$_[1]}) {
			return $misc{queue}{$misc{counter}}{$_[0]}{$_[1]};
		} else {
			return $_[2];
		}
	} else {
		return 0;
	}
}

sub set_settings {
	# setting changed/added => change/add it here

	# boolean
	$option{dau_babble_verbose}                  = Irssi::settings_get_bool('dau_babble_verbose');
	$option{dau_cowsay_print_cow}                = Irssi::settings_get_bool('dau_cowsay_print_cow');
	$option{dau_figlet_print_font}               = Irssi::settings_get_bool('dau_figlet_print_font');
	$option{dau_statusbar_daumode_hide_when_off} = Irssi::settings_get_bool('dau_statusbar_daumode_hide_when_off');
	$option{dau_tab_completion}                  = Irssi::settings_get_bool('dau_tab_completion');

	# Integer
	$option{dau_babble_verbose_minimum_lines}    = Irssi::settings_get_int('dau_babble_verbose_minimum_lines');
	$option{dau_remote_babble_interval}          = Irssi::settings_get_int('dau_remote_babble_interval');
	$option{dau_remote_babble_interval_accuracy} = Irssi::settings_get_int('dau_remote_babble_interval_accuracy');

	# String
	$option{dau_babble_standard_options}         = Irssi::settings_get_str('dau_babble_standard_options');
	$option{dau_cowsay_cowlist}                  = Irssi::settings_get_str('dau_cowsay_cowlist');
	$option{dau_cowsay_cowpath}                  = Irssi::settings_get_str('dau_cowsay_cowpath');
	$option{dau_cowsay_cowpolicy}                = Irssi::settings_get_str('dau_cowsay_cowpolicy');
	$option{dau_cowsay_cowsay_path}              = Irssi::settings_get_str('dau_cowsay_cowsay_path');
	$option{dau_cowsay_cowthink_path}            = Irssi::settings_get_str('dau_cowsay_cowthink_path');
	$option{dau_delimiter_string}                = Irssi::settings_get_str('dau_delimiter_string');
	$option{dau_figlet_fontlist}                 = Irssi::settings_get_str('dau_figlet_fontlist');
	$option{dau_figlet_fontpath}                 = Irssi::settings_get_str('dau_figlet_fontpath');
	$option{dau_figlet_fontpolicy}               = Irssi::settings_get_str('dau_figlet_fontpolicy');
	$option{dau_figlet_path}                     = Irssi::settings_get_str('dau_figlet_path');
	$option{dau_files_babble_messages}           = Irssi::settings_get_str('dau_files_babble_messages');
	$option{dau_files_moron_own_substitutions}   = Irssi::settings_get_str('dau_files_moron_own_substitutions');
	$option{dau_files_root_directory}            = Irssi::settings_get_str('dau_files_root_directory');
	$option{dau_moron_eol_style}                 = Irssi::settings_get_str('dau_moron_eol_style');
	$option{dau_moron_substitutions_permissions} = Irssi::settings_get_str('dau_moron_substitutions_permissions');
	$option{dau_random_options}                  = Irssi::settings_get_str('dau_random_options');
	$option{dau_remote_babble_channellist}       = Irssi::settings_get_str('dau_remote_babble_channellist');
	$option{dau_remote_babble_channelpolicy}     = Irssi::settings_get_str('dau_remote_babble_channelpolicy');
	$option{dau_remote_channellist}              = Irssi::settings_get_str('dau_remote_channellist');
	$option{dau_remote_channelpolicy}            = Irssi::settings_get_str('dau_remote_channelpolicy');
	$option{dau_remote_deop_reply}               = Irssi::settings_get_str('dau_remote_deop_reply');
	$option{dau_remote_devoice_reply}            = Irssi::settings_get_str('dau_remote_devoice_reply');
	$option{dau_remote_op_reply}                 = Irssi::settings_get_str('dau_remote_op_reply');
	$option{dau_remote_permissions}              = Irssi::settings_get_str('dau_remote_permissions');
	$option{dau_remote_question_reply}           = Irssi::settings_get_str('dau_remote_question_reply');
	$option{dau_remote_voice_reply}              = Irssi::settings_get_str('dau_remote_voice_reply');
	$option{dau_standard_messages}               = Irssi::settings_get_str('dau_standard_messages');
	$option{dau_standard_options}                = Irssi::settings_get_str('dau_standard_options');
	$option{dau_words_range}                     = Irssi::settings_get_str('dau_words_range');
}

sub signal_handling {
	# complete word

	if ($option{dau_tab_completion}) {
		if ($misc{signals}{'complete word'} != 1) {
			Irssi::signal_add_last('complete word', 'signal_complete_word');
		}
		$misc{signals}{'complete word'} = 1;
	} else {
		if ($misc{signals}{'complete word'} != 0) {
			Irssi::signal_remove('complete word', 'signal_complete_word');
		}
		$misc{signals}{'complete word'} = 0;
	}

	# event privmsg

	if ($option{dau_remote_permissions} =~ /^1[01][01][01][01][01]$/) {
		if ($misc{signals}{'event privmsg'} != 1) {
			Irssi::signal_add_last('event privmsg', 'signal_event_privmsg');
		}
		$misc{signals}{'event privmsg'} = 1;
	} else {
		if ($misc{signals}{'event privmsg'} != 0) {
			Irssi::signal_remove('event privmsg', 'signal_event_privmsg');
		}
		$misc{signals}{'event privmsg'} = 0;
	}

	# nick mode changed

	if ($option{dau_remote_permissions} =~ /^[01]1[01][01][01][01]$/ ||
	    $option{dau_remote_permissions} =~ /^[01][01]1[01][01][01]$/ ||
	    $option{dau_remote_permissions} =~ /^[01][01][01]1[01][01]$/ ||
	    $option{dau_remote_permissions} =~ /^[01][01][01][01]1[01]$/)
	{
		if ($misc{signals}{'nick mode changed'} != 1) {
			Irssi::signal_add_last('channel joined', 'build_nick_mode_struct');
			Irssi::signal_add_last('nick mode changed', 'signal_nick_mode_changed');
		}
		$misc{signals}{'nick mode changed'} = 1;
	} else {
		if ($misc{signals}{'nick mode changed'} != 0) {
			Irssi::signal_remove('channel joined', 'build_nick_mode_struct');
			Irssi::signal_remove('nick mode changed', 'signal_nick_mode_changed');
		}
		$misc{signals}{'nick mode changed'} = 0;
	}

	# send text

	my $odaumode = 0;

	foreach my $server (keys %{ $misc{daumode_ochannels} }) {
		foreach my $channel (keys %{ $misc{daumode_ochannels}{$server} }) {
			if ($misc{daumode_ochannels}{$server}{$channel} == 1) {
				$odaumode = 1;
			}
		}
	}

	if ($odaumode) {
		if ($misc{signals}{'send text'} != 1) {
			Irssi::signal_add_first('send text', 'signal_send_text');
		}
		$misc{signals}{'send text'} = 1;
	} else {
		if ($misc{signals}{'send text'} != 0) {
			Irssi::signal_remove('send text', 'signal_send_text');
		}
		$misc{signals}{'send text'} = 0;
	}

	# signals idaumode (incoming messages - daumode)

	my $idaumode = 0;

	foreach my $server (keys %{ $misc{daumode_ichannels} }) {
		foreach my $channel (keys %{ $misc{daumode_ichannels}{$server} }) {
			if ($misc{daumode_ichannels}{$server}{$channel} == 1) {
				$idaumode = 1;
			}
		}
	}

	if ($idaumode) {
		if ($misc{signals}{'signals idaumode'} != 1) {
			Irssi::signal_add_last('message public', 'signals_idaumode');
			Irssi::signal_add_last('message irc action', 'signals_idaumode');
		}
		$misc{signals}{'signals idaumode'} = 1;
	} else {
		if ($misc{signals}{'signals idaumode'} != 0) {
			Irssi::signal_remove('message public', 'signals_idaumode');
			Irssi::signal_remove('message irc action', 'signals_idaumode');
		}
		$misc{signals}{'signals idaumode'} = 0;
	}
}

################################################################################
# Debugging
################################################################################

#BEGIN {
#	use warnings;
#
#	open(STDERR, ">> dau-stderr") or print "STDERR redirect failed: $!";
#}