+void
+part_all_channels(struct userNode *target)
+{
+ unsigned int n=0;
+ struct modeNode *mn;
+
+ for (n=0; n<target->channels.used; n++) {
+ mn = target->channels.list[n];
+ irc_svspart(webtv, target, mn->channel);
+ }
+
+ return;
+}
+
+static MODCMD_FUNC(cmd_sjoin)
+{
+ struct userNode *bot = cmd->parent->bot;
+
+ if (!IsChannelName(argv[1])) {
+ reply("MSG_NOT_CHANNEL_NAME");
+ return 0;
+ } else if (!(channel = GetChannel(argv[1]))) {
+ channel = AddChannel(argv[1], now, NULL, NULL, NULL);
+ AddChannelUser(bot, channel)->modes |= MODE_CHANOP;
+ } else if (GetUserMode(channel, bot)) {
+ reply("WBMSG_ALREADY_JOINED", channel->name);
+ return 0;
+ } else {
+ struct mod_chanmode change;
+ mod_chanmode_init(&change);
+ change.argc = 1;
+ change.args[0].mode = MODE_CHANOP;
+ change.args[0].u.member = AddChannelUser(bot, channel);
+ modcmd_chanmode_announce(&change);
+ }
+ irc_fetchtopic(bot, channel->name);
+ reply("WBMSG_JOIN_DONE", channel->name);
+ return 1;
+}
+
+static MODCMD_FUNC(cmd_join)
+{
+ struct chanNode *target;
+
+ if (!check_mark(cmd, user, NULL, 0, 0, NULL))
+ return 0;
+
+ if(!(target = GetChannel(argv[1])))
+ {
+ reply("MSG_INVALID_CHANNEL");
+ return 0;
+ }
+
+ if (trace_check_bans(user, target) == 1) {
+ reply("WBMSG_CHANNEL_BANNED", argv[1]);
+ return 0;
+ }
+
+ if (target->modes & MODE_INVITEONLY) {
+ reply("WBMSG_CHANNEL_INVITE", argv[1]);
+ return 0;
+ }
+
+
+ if (target->limit > 0) {
+ if (target->members.used >= target->limit) {
+ reply("WBMSG_CHANNEL_LIMIT", argv[1]);
+ return 0;
+ }
+ }
+
+
+ if (*target->key) {
+ if (argc > 2) {
+ if (strcmp(argv[2], target->key)) {
+ reply("WBMSG_CHANNEL_PASSWORD", argv[1]);
+ return 0;
+ }
+ } else {
+ reply("WBMSG_CHANNEL_PASSWORD", argv[1]);
+ return 0;
+ }
+ }
+
+ part_all_channels(user);
+ irc_svsjoin(webtv, user, target);
+ return 1;
+}
+
+static MODCMD_FUNC(cmd_part)
+{
+ struct mod_chanmode change;
+ struct chanNode *target;
+
+ if (!check_mark(cmd, user, NULL, 0, 0, NULL))
+ return 0;
+
+ if(!(target = GetChannel(argv[1])))
+ {
+ reply("MSG_INVALID_CHANNEL");
+ return 0;
+ }
+
+ mod_chanmode_init(&change);
+ change.argc = 1;
+ change.args[0].u.member = GetUserMode(target, user);
+ if(!change.args[0].u.member)
+ {
+ if(argc)
+ reply("MSG_CHANNEL_ABSENT", target->name);
+ return 0;
+ }
+
+ irc_svspart(webtv, user, target);
+ return 1;
+}
+