Created
October 8, 2015 10:48
-
-
Save redwallhp/8b89eef0875f72113d3f to your computer and use it in GitHub Desktop.
CHClanChat -> NerdClanChat Migration Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc(_chce_reset_database, | |
@result = query("clanchatexport", "SELECT name FROM sqlite_master WHERE type='table' AND name='clanchat_channels'") | |
if (array_size(@result) > 0) { | |
msg("Existing export tables found. Deleting.") | |
@result = query("clanchatexport", "DROP TABLE clanchat_bulletins;") | |
@result = query("clanchatexport", "DROP TABLE clanchat_channels;") | |
@result = query("clanchatexport", "DROP TABLE clanchat_invites;") | |
@result = query("clanchatexport", "DROP TABLE clanchat_members;") | |
@result = query("clanchatexport", "DROP TABLE clanchat_playermeta;") | |
} | |
) | |
proc(_chce_create_tables, | |
msg("Creating tables") | |
@result = query("clanchatexport", "CREATE TABLE `clanchat_bulletins` (`id` integer, `channel` varchar(255) NOT NULL, `message` varchar(255) NOT NULL, PRIMARY KEY(id));") | |
@result = query("clanchatexport", "CREATE TABLE `clanchat_channels` (`id` integer, `name` varchar(255) NOT NULL, `owner` varchar(255) NOT NULL, `color` varchar(255) NOT NULL, `text_color` varchar(255) NOT NULL, `alert_color` varchar(255) NOT NULL, `pub` integer(1), `secret` integer(1), PRIMARY KEY(id));") | |
@result = query("clanchatexport", "CREATE TABLE `clanchat_invites` (`id` integer, `channel` varchar(255) NOT NULL, `uuid` varchar(255) NOT NULL, PRIMARY KEY(id));") | |
@result = query("clanchatexport", "CREATE TABLE `clanchat_members` (`id` integer, `channel` varchar(255) NOT NULL, `uuid` varchar(255) NOT NULL, `name` varchar(255), `manager` integer(1), `subscribed` integer(1), PRIMARY KEY(id));") | |
@result = query("clanchatexport", "CREATE TABLE `clanchat_playermeta` (`id` integer, `uuid` varchar(255) NOT NULL, `name` varchar(255), `last_received` varchar(255), `default_channel` varchar(255), PRIMARY KEY(id));") | |
) | |
proc(_chce_reformat_uuid, @uuid, | |
@one = substr(@uuid, 0, 8) | |
@two = substr(@uuid, 8, 12) | |
@three = substr(@uuid, 12, 16) | |
@four = substr(@uuid, 16, 20) | |
@five = substr(@uuid, 20) | |
@str = @one . '-' . @two . '-' . @three . '-' . @four . '-' . @five | |
return(@str) | |
) | |
proc(_cc_get_channel_info, @channel, | |
@channel = to_lower(@channel) | |
@channelInfo = _cc_get_value('clanchat.channels.'.@channel, null) | |
if(@channelInfo == null){ | |
die(color(RED).'The channel "'.@channel.'" doesn\'t exist') | |
} else { | |
@keys = array_keys(@channelInfo); | |
if(!array_contains(@keys, 'flags')) { | |
@channelInfo['flags'] = array( | |
public: false, | |
secret: false | |
) | |
} | |
if(!array_contains(@keys, 'bulletins')) { | |
@channelInfo['bulletins'] = array() | |
} | |
if(!array_contains(@keys, 'textcolor')) { | |
@channelInfo['textcolor'] = GRAY | |
} | |
if(!array_contains(@keys, 'alertcolor')) { | |
@channelInfo['alertcolor'] = GRAY | |
} | |
@uniqueMembers = array_unique(@channelInfo['members']); | |
if (array_size(@uniqueMembers) != array_size(@channelInfo['members'])) { | |
@channelInfo['members'] = array_unique(@channelInfo['members']) | |
_cc_save_channel_info(@channel, @channelInfo) | |
} | |
return(@channelInfo) | |
} | |
) | |
proc(_chce_export_channels, | |
msg("Exporting channel data. This may take awhile.") | |
@channels = _cc_get_value('clanchat.channels', array()) | |
foreach(@channels, @channel, | |
@info = _cc_get_channel_info(@channel) | |
@pub = 0 | |
@sec = 0 | |
if (@info['flags']['public'] == true) { @pub = 1 } | |
if (@info['flags']['secret'] == true) { @sec = 1 } | |
@owner = _chce_reformat_uuid(@info['owner']) | |
@result = query("clanchatexport", "INSERT INTO `clanchat_channels` (name, owner, color, text_color, alert_color, pub, secret) VALUES(?, ?, ?, ?, ?, ?, ?);", @channel, @owner, @info['color'], @info['textcolor'], @info['alertcolor'], @pub, @sec) | |
_chce_export_channel_bulletins(@channel, @info['bulletins']) | |
_chce_export_channel_members(@channel, @info) | |
) | |
) | |
proc(_chce_export_channel_bulletins, @channel, @bulletins, | |
foreach(@bulletins, @bulletin, | |
@result = query("clanchatexport", "INSERT INTO `clanchat_bulletins` (channel, message) VALUES(?, ?);", @channel, @bulletin) | |
) | |
) | |
proc(_chce_export_channel_members, @channel, @info, | |
@managers = @info['managers'] | |
foreach(@info['members'], @member, | |
@is_manager = 0; | |
if (array_contains(@managers, @member)) { @is_manager = 1 } | |
@name = _get_username_from_uuid(@member) | |
@uuid = _chce_reformat_uuid(@member) | |
@result = query("clanchatexport", "INSERT INTO `clanchat_members` (channel, uuid, name, manager, subscribed) VALUES(?, ?, ?, ?, ?);", @channel, @uuid, @name, @is_manager, 1) | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nerdch.level.admin:/exportclanchat = >>> | |
msg("Starting export process.") | |
_chce_reset_database() | |
_chce_create_tables() | |
_chce_export_channels() | |
msg("Export done!") | |
<<< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment